How do I make a form submit button active only if a single option box is checked (or ticked), preferably onpage, and in php? Thanks, and... Be Well! ECS Dave
here is an example for you found on sitepoint <SCRIPT LANGUAGE="JavaScript"> function verifForm(formulaire) { if(formulaire.tick.checked == false) alert('Please check the box'); else formulaire.submit(); } </SCRIPT> <body> <FORM> <input name="tick" type="checkbox"> <INPUT name="Submit" TYPE="submit" onClick="verifForm(this.form)" VALUE="submit" > </FORM> </body> </html> HTML:
Thanks, but I don't seem to be able to get your code to work. I placed the script section first into the head section of my webpage, added the code to my form, then tested it... No luck. Then tried it with the script in the body section, still no luck. Thanks for trying though! Be Well! ECS Dave P.S. php won't do this?!?!?
Thanks Man! Here's the form code: <form action="index.php" method="post"> User entered form fields are here <input name="signup" type="submit" value="Sign Me Up!"> <input type="hidden" name="action" value="affsignup"> </form> Code (markup): and the box I want required to be checked is: <input name="Iagree" type="checkbox"> Code (markup): Be Well! ECS Dave
<?php if(isset($_POST['Iagree'])){ $Iagree = $_POST['Iagree']; } if($Iagree != 'checked'){ //show error else{ //proceed with processing } //Note below I added a value to the check box /*/ // Also I only have this using print to show the admin notes better and via php. you can end the php before the html with ?> and start it back up after the html with <?php /*/ print ' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="index.php" method="post"> <p>User entered form fields are here</p> <p><input name="signup" type="submit" value="Sign Me Up!"></p> <p><input type="hidden" name="action" value="affsignup"></p> <p><input name="Iagree" type="checkbox" value="checked"> You must check this box</p> </form> </body> </html>'; ?> PHP:
I really appreciate what you've done! Really! Prior to getting the instant email notification of your post, I had asked in another forum, and they had suggested a solution to my quandary. I tried it, and it worked (albeit with some "messing about", on my part, with the referenced code)! You can see the resultant page at http://trustedsalesstore.com/shop/jv.php where, unless the checkbox is checked (or ticked, as some say), the submit button cannot be pressed... Thanks again for your efforts, and a big REP to you for them!!! Be Well! ECS Dave