stulk stulk -4 years ago 128
Javascript Question

setting an option value empty in a dynamically changing select list

How can I modify this code:

https://jsfiddle.net/nn83qf3y/

so that the '--None--' selections are outputted as

<option value="">--None--</option>


instead of

<option value="--None--">--None--</option>


Thanks.

Answer Source

Didn't put much time into your question, So here's a simple fix.

if(programs[i][1] == '--None--') {
    var opt = new Option(programs[i][1],'' );
}else{
    opt = new Option(programs[i][1]);
}

https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionElement/Option

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download