I'm sorry, didn't realize that was a function I built to add an option. Here is the way to add an option:
<script type="text/javascript">
function chkChange(ddl)
{
var textbox = document.getElementById("<%= txtdept.ClientID %>");
if (ddl.options[ddl.selectedIndex].value == "New Department")
{
elm.onblur = function() { addOptionOnBlur(this); };
textbox.style.display = "block";
textbox.focus();
}
else
{
textbox.style.display = "none";
}
}
function addOptionOnBlur(elm)
{
if (elm.value.length > 0 && elm.value.replace(/ /g, "").length > 0)
{
document.getElementById("<%= ddldept.ClientID %>").options.add(newOption(elm.value, elm.value));
}
}
function newOption(val, txt)
{
var option = document.createElement("OPTION");
option.text = txt;
option.value = val;
return option;
}
</script>
This will add an option to the dropdownlist everytime the textbox loses focus, as long as the value is empty and isn't only spaces.
Reputation Points: 43
Solved Threads: 68
Veteran Poster
Offline 1,080 posts
since Sep 2007