jesushax Posted October 13, 2008 Share Posted October 13, 2008 Hi all, as the title heopfully explains i have to checkboxes on my form if neither of them are checked id like to display an error message and dont submit until one of them has a tick in it can anyone help me out? Cheers Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted October 13, 2008 Share Posted October 13, 2008 Yup, give your checkboxes different ID's. <input type="checkbox" name="checkbox1" id="checkbox1" value="check1_value" /><br /> <input type="checkbox" name="checkbox2" id="checkbox2" value="check2_value" /> Then make a JavaScript function. <script language="javascript"> function checkboxes(){ var check1 = document.getElementById("checkbox1"); var check2 = document.getElementById("checkbox2"); if(check1.checked || check2.checked){ return true; }else{ alert("Please check a box!"); return false; } } </script> Then in you're submit button you need to call the function but with a return beforehand. <input type="submit" name="submit" id="submit" onclick="return checkboxes();" /> Good luck. Quote Link to comment 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.