How do I compare two picklists or select boxes in JavaScript? Compare lists. Check two combo boxes are the same.
How do I compare two picklists or select boxes in JavaScript? Compare lists. Check two combo boxes are the same.
| Answer | function compareSelectBox(formName1,selectBox1,formName2,selectBox2,msg,focusFlag)
{
valueofSelect1 = eval(formName1 + "." + selectBox1 + ".options[" + formName1 + "." + selectBox1 + ".selectedIndex]" + ".value");
if (eval(formName2+"."+selectBox2))
valueofSelect2 = eval(formName2 + "." + selectBox2 + ".options[" + formName2 + "." + selectBox2 + ".selectedIndex]" + ".value");
else
valueofSelect2 = valueofSelect1+"1";
if ( valueofSelect1 == valueofSelect2 )
{
alert(msg);
if (focusFlag==1)
{
eval(formName1 + "."+ selectBox1 +".focus()");
}
else
{
eval(formName2 + "."+ selectBox2 +".focus()");
}
return false;
}
return true;
} |
| Attachments | -none- |
| Applies to versions | |
| FAQ Provided By | Steven Charles Robinson |
| Credit | |
 |  |
|
|