Welcome to WebmasterWorld Guest from 54.225.51.21

Forum Moderators: open

Message Too Old, No Replies

disable/enable submit button

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

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

Junior Member

10+ Year Member

joined:Aug 21, 2003
posts:74
votes: 0


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

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

Senior Member from US 

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

joined:Oct 17, 2005
posts:4996
votes: 14


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.
12:32 pm on Nov 29, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Aug 21, 2003
posts:74
votes: 0


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;"/>

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members