sent parameter new Option(this.name, this.id) to function error
sent parameter new Option(this.name, this.id) to function error
ballprogrammer
Posts: 11Questions: 0Answers: 0
html
[code]
abc
[/code]
data
[code]
data1 = [ { "id": "1", "name": "name1" },
{ "id": "2", "name": "name2" },
{ "id": "3", "name": "name3" }];
data2 = [ { "id": "1", "value": "value1" },
{ "id": "2", "value": "value2" },
{ "id": "3", "value": "value3" }];
data3 = [ { "id": "1", "text": "text1" },
{ "id": "2", "text": "text2" },
{ "id": "3", "text": "text3" }];
[/code]
script
[code]
$('#select1').empty();
$('#select1').append(new Option("name0", 0));
$.each(org_position, function () {
$('#select1').append(new Option(this.name, this.id));
});
[/code]
is ok select option data
problem
i want create function to
[code]
function set_select_option(select_name, start_value, data, new_option) {
select_name.empty();
select_name.append(new Option(start_value.toString(), 0));
$.each(data, function () {
select_name.append(new_option) ;
});
};
[/code]
i want use this
[code]
set_select_option('#select1', 'name0', data1, new Option(this.name, this.id));
[/code]
this error
[code]
Option(this.name, this.id)
[/code]
how to fix ?
[code]
abc
[/code]
data
[code]
data1 = [ { "id": "1", "name": "name1" },
{ "id": "2", "name": "name2" },
{ "id": "3", "name": "name3" }];
data2 = [ { "id": "1", "value": "value1" },
{ "id": "2", "value": "value2" },
{ "id": "3", "value": "value3" }];
data3 = [ { "id": "1", "text": "text1" },
{ "id": "2", "text": "text2" },
{ "id": "3", "text": "text3" }];
[/code]
script
[code]
$('#select1').empty();
$('#select1').append(new Option("name0", 0));
$.each(org_position, function () {
$('#select1').append(new Option(this.name, this.id));
});
[/code]
is ok select option data
problem
i want create function to
[code]
function set_select_option(select_name, start_value, data, new_option) {
select_name.empty();
select_name.append(new Option(start_value.toString(), 0));
$.each(data, function () {
select_name.append(new_option) ;
});
};
[/code]
i want use this
[code]
set_select_option('#select1', 'name0', data1, new Option(this.name, this.id));
[/code]
this error
[code]
Option(this.name, this.id)
[/code]
how to fix ?
This discussion has been closed.
Replies
Allan
Allan