argan328 Posted March 8, 2007 Share Posted March 8, 2007 Hi! I picked this script up from a posting here over a year ago and it's exactly what I need...the submit button is supposed to be disabled until the user checks the box that he/she has read the terms of use... the problem is that if the user clicks on the submit button it becomes enabled along with the check box at the same time. I want the submit button to remain disabled until the user specifically clicks on the checkbox. <script language="javascript"> function Activate() { check_box = document.getElementById('checkbox'); button = document.getElementById('Submit'); if ( check_box.checked == true ) { button.disabled = false; } else button.disabled = true; } </script> <form id="form1" name="form1" method="post" action=""> <label> <input type="checkbox" name="checkbox" id="checkbox" value="0" onClick="Activate()"/> <br /> <input type="submit" name="Submit" id='Submit' value="Submit" disabled /> </label> </form> Can anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/41715-solved-submit-button-remain-disabled-until-checkbox-checked/ Share on other sites More sharing options...
warewolfe Posted March 8, 2007 Share Posted March 8, 2007 Off the top of my head Make the Submit a class with the style of visibility:hidden and then set it to visibility:visible in the Activate function with a innerHTML call. Quote Link to comment https://forums.phpfreaks.com/topic/41715-solved-submit-button-remain-disabled-until-checkbox-checked/#findComment-202251 Share on other sites More sharing options...
argan328 Posted March 8, 2007 Author Share Posted March 8, 2007 forgive me I'm still a newbie, by "make the submit a class do you mean something like this: submit { visibility:hidden } or <STYLE> .vis1 { visibility:visible } .vis2 { visibility:hidden } </STYLE> and then how would I set it to visibility:visible in my Activate function? Thanks Argan Quote Link to comment https://forums.phpfreaks.com/topic/41715-solved-submit-button-remain-disabled-until-checkbox-checked/#findComment-202265 Share on other sites More sharing options...
fenway Posted March 8, 2007 Share Posted March 8, 2007 You could just set the visibility style attribute directly, no need for class. Quote Link to comment https://forums.phpfreaks.com/topic/41715-solved-submit-button-remain-disabled-until-checkbox-checked/#findComment-202521 Share on other sites More sharing options...
obsidian Posted March 8, 2007 Share Posted March 8, 2007 Here's my "off the cuff" solution: <script type="text/javascript"> function checkSubmit(ele, id) { x = document.getElementById(id); if (ele.checked == true) x.disabled = false; else x.disabled = true; } </script> <input type="checkbox" name="myCheck" onclick="checkSubmit(this, 'mySubmit')" value="y" /> <input type="submit" name="submit" value="Submit" id="mySubmit" disabled="disabled" /> Quote Link to comment https://forums.phpfreaks.com/topic/41715-solved-submit-button-remain-disabled-until-checkbox-checked/#findComment-202579 Share on other sites More sharing options...
argan328 Posted March 8, 2007 Author Share Posted March 8, 2007 wow I can't wait until I can code like this 'off the cuff'! It still takes me 10 minutes just to arrange a proper IF statement! Thanks all! Argan Quote Link to comment https://forums.phpfreaks.com/topic/41715-solved-submit-button-remain-disabled-until-checkbox-checked/#findComment-202822 Share on other sites More sharing options...
fenway Posted March 8, 2007 Share Posted March 8, 2007 You can be really fancy and say: x.disabled = !ele.checked But that's not really robust. Quote Link to comment https://forums.phpfreaks.com/topic/41715-solved-submit-button-remain-disabled-until-checkbox-checked/#findComment-202999 Share on other sites More sharing options...
obsidian Posted March 9, 2007 Share Posted March 9, 2007 You can be really fancy and say: x.disabled = !ele.checked But that's not really robust. Haha! Leave it to fenway Quote Link to comment https://forums.phpfreaks.com/topic/41715-solved-submit-button-remain-disabled-until-checkbox-checked/#findComment-203095 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.