venki.ffcl
06-08-2009, 02:28 PM
Dear friends,
Here i have a problem when am comparing two string values.
1. Am using a ListBox Control with the name "LB"
2. Am getting user input using a textbox control named "txtname"
3. The condition is not satisfied while am comparing the listbox values by textbox values. But both the returned values are same when checked by alert.
Note : I need to insert the user Input if it is not exists in the listbox.
Please anyone guide me
Code Used
----------
function OnGetHelloDetails(result) {
if (!result) {
if ($get('<%=LB.ClientID %>').length > 0) {
for (var i = 0; i < $get('<%=LB.ClientID %>').length; i++) {
if (($get('<%=LB.ClientID %>').options[i].value) == ($get('txtname').value)) {
break;
}
else {
var opt = document.createElement('OPTION');
opt.text = $get('txtname').value;
opt.value = $get('txtname').value;
$get('<%=LB.ClientID %>').options.add(opt);
}
}
}
else {
var opt = document.createElement('OPTION');
opt.text = $get('txtname').value;
opt.value = $get('txtname').value;
$get('<%=LB.ClientID %>').options.add(opt);
}
}
}
Here i have a problem when am comparing two string values.
1. Am using a ListBox Control with the name "LB"
2. Am getting user input using a textbox control named "txtname"
3. The condition is not satisfied while am comparing the listbox values by textbox values. But both the returned values are same when checked by alert.
Note : I need to insert the user Input if it is not exists in the listbox.
Please anyone guide me
Code Used
----------
function OnGetHelloDetails(result) {
if (!result) {
if ($get('<%=LB.ClientID %>').length > 0) {
for (var i = 0; i < $get('<%=LB.ClientID %>').length; i++) {
if (($get('<%=LB.ClientID %>').options[i].value) == ($get('txtname').value)) {
break;
}
else {
var opt = document.createElement('OPTION');
opt.text = $get('txtname').value;
opt.value = $get('txtname').value;
$get('<%=LB.ClientID %>').options.add(opt);
}
}
}
else {
var opt = document.createElement('OPTION');
opt.text = $get('txtname').value;
opt.value = $get('txtname').value;
$get('<%=LB.ClientID %>').options.add(opt);
}
}
}