homepage Welcome to WebmasterWorld Guest from 54.237.38.30
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
disable/enable submit button
2 option must be selected to enable, and disable when unselected
LinuxGold

10+ Year Member



 
Msg#: 4735 posted 4:19 pm on Nov 28, 2005 (gmt 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

 

Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4735 posted 4:37 pm on Nov 28, 2005 (gmt 0)

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

10+ Year Member



 
Msg#: 4735 posted 12:32 pm on Nov 29, 2005 (gmt 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;"/>


Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved