homepage Welcome to WebmasterWorld Guest from 54.163.72.86
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
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




msg:1482509
 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




msg:1482510
 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




msg:1482511
 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