>Enabled >Disabled
...
function my_field_change()
{
var my_value = document.forms[0].my_field.value;
...
if (dhcp_relay == "1") {
document.forms[0].some_other_field.disabled = 1;
}
...
}
In the function "开发者_高级运维my_field_change()" I'm expecting to have 'my_value' equal to either 1 or 0, bit it won't happen. What am I doing wrong?
You have to get the value associated with the selected index:
var my_value = document.forms[0].my_field[document.forms[0].my_field.selectedIndex].value;
If you can't get that to work, another option is to update the html to use an id, and reference that id specifically in the javascript:
<select id="my_field" name="my_field" onChange="my_field_change();">
<option value="1" <% nvram_match("my_field", "1", "selected"); %>>Enabled</option>
<option value="0" <% nvram_match("my_field", "0", "selected"); %>>Disabled</option>
</select>
...
function my_field_change()
{
var select = document.getElementById("my_field");
var my_value = select[select.selectedIndex].value;
...
}
精彩评论