You are here: irt.org | FAQ | JavaScript | Form | Q1553 [ previous next ]
Try this:
<script language="JavaScript"><!-- function addOption(sText,sValue) { var found = false; for (i=0,n=document.myForm.mySelect.options.length;i<n;i++) { if (document.myForm.mySelect.options[i].value == sValue) { found = true; break; } } if (!found) { document.myForm.mySelect.options.length++; // first add one (Internet Explorer 5 fix) document.myForm.mySelect.options.[document.myForm.mySelect.options.length-1] = new Option(sText,sValue); } return !found; // returns true if insertion took place } if (addOption('Looking For','needle')) alert('New option added'); //--></script>