Add OPTION to SELECT


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function addSelectOption(formName, selectName, optionValue, optionText, insertIndex, selectedOptionIndex) {
  2. var newOpt = document.createElement("option");
  3. newOpt.value = optionValue;
  4. newOpt.text = optionText;
  5. var selectElement = eval("document." + formName + "." + selectName);
  6. selectElement.add(newOpt, selectElement.options[insertIndex]);
  7. selectElement.selectedIndex = selectedOptionIndex;
  8. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.