My questions is: how can this be rewritten so it will enable/disable other textfields associated with other dropdown menus? (as if we have the same code, but the select name "D2", "D3"...etc. and text field to enable associated with that select: "otherz2", "otherz3".
Start by validating your code. It will not pass. Among other things, you use uppercase letters in attribute names, such as onChange, which is valid HTML but invalid XHTML. Then you close your input tags with /> which is valid XHTML and invalid HTML.
I changed a few of the name attributes when I rebuilt this, so you'll have to adjust the code. Javascript:
'D1' select option 'Others'.
HTML
<select size="1" name="D1" onChange="dis_able()">
<option>Category A</option>
<option>Category B</option>
<option>Category C</option>
<option value="Others">Others</option>
</select>
<input disabled type="text" name="otherz" size="20" value="pls specify"></p>
Javascript
function dis_able()
{
if(document.myform.D1.value != 'Others')
document.myform.otherz.disabled=1;
else
document.myform.otherz.disabled=0;
}
My questions is: how can this be rewritten so it will enable/disable other textfields associated with other dropdown menus? (as if we have the same code, but the select name "D2", "D3"...etc. and text field to enable associated with that select: "otherz2", "otherz3".
Thank you for your help.
I changed a few of the name attributes when I rebuilt this, so you'll have to adjust the code.
Javascript:
function disable_input() {if( document.form.categories.value == 'other' ) {
document.form.other.disabled = false;
}else {
document.form.other.disabled = true;
}
}
HTML: