Welcome to WebmasterWorld Guest from 54.196.175.173

Forum Moderators: open

Message Too Old, No Replies

disable/enable submit button

2 option must be selected to enable, and disable when unselected

     

LinuxGold

4:19 pm on Nov 28, 2005 (gmt 0)

10+ Year Member



Is there a way to disable submit button at startup and enable it if both options are selected and disable again if one of them (or both) are returned to its original state (nothing)?

Scott

Fotiman

4:37 pm on Nov 28, 2005 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Set your button to be disabled by default. Then add an onchange event handler to your select element. The handler should determine what is selected, and then enable/disable your submit button per your requirements.

LinuxGold

12:32 pm on Nov 29, 2005 (gmt 0)

10+ Year Member



Thanks!

Here is the source in case anyone want to learn:


<script type="text/javascript">
function dis_ena_submit()
{
if(document.acc_ctrl.add_access.options[0].selected document.acc_ctrl.add_assoc.options[0].selected)
{
//Disables submit button
document.forms[0].grant_button.disabled=true;
}
else
{
//Enables submit button
document.forms[0].grant_button.disabled=false;
}
}
</script>

...
<body id="access_control" onload="document.forms[0].grant_button.disabled=true;">
...
<select id="label_add_access" name="add_access" onChange="dis_ena_submit('add_access');">
...
<select id="label_add_assoc" name="add_assoc" onChange="dis_ena_submit('add_assoc');">
...
<input type="submit" value="Grant" name="grant_button" />
<input type="reset" onclick="document.forms[0].grant_button.disabled=true;"/>

 

Featured Threads

Hot Threads This Week

Hot Threads This Month