How do I use JavaScript (or ASP) to change enable a disabled form element, based on the option selected in the previous drop-down menu? I have two drop-down menus, and only want the second to be enabled if certain options are selected on the first option.
thanks!
How do I use JavaScript (or ASP) to change enable a disabled form element?
Basically you just need to write a function that handles the Select element's OnChange event:
function Verify()
{
//Find the selected ID
var SelectedID = document.getElementById( 'lstOne' ).value
if (SelectedID == -1 || SelectedID == 3)
{
//Disable the second list
document.getElementById( 'lstTwo' ).disabled = true;
}
else
{
//Enable the second list
document.getElementById( 'lstTwo' ).disabled = false;
}
}
Your form will simply look like this:
%26lt;form%26gt;
%26lt;select OnChange="Verify()" id="lstOne"%26gt;
%26lt;option value="-1" selected%26gt;Please select a number%26lt;/option%26gt;
%26lt;option value="1"%26gt;1%26lt;/option%26gt;
%26lt;option value="2"%26gt;2%26lt;/option%26gt;
%26lt;option value="3"%26gt;3%26lt;/option%26gt;
%26lt;option value="4"%26gt;4%26lt;/option%26gt;
%26lt;/select%26gt;
%26lt;select id="lstTwo" disabled="True"%26gt;
%26lt;option value="Ford"%26gt;Ford%26lt;/option%26gt;
%26lt;option value="Chevy"%26gt;Chevy%26lt;/option%26gt;
%26lt;option value="Honda"%26gt;Honda%26lt;/option%26gt;
%26lt;option value="Toyota"%26gt;Toyota%26lt;/option%26gt;
%26lt;/select%26gt;
%26lt;/form%26gt;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment