/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function addSelectOption(formName, selectName, optionValue, optionText, insertIndex, selectedOptionIndex) { var newOpt = document.createElement("option"); newOpt.value = optionValue; newOpt.text = optionText; var selectElement = eval("document." + formName + "." + selectName); selectElement.add(newOpt, selectElement.options[insertIndex]); selectElement.selectedIndex = selectedOptionIndex; }