n1concepts Posted October 16, 2011 Share Posted October 16, 2011 Hi, I have some javascript defined that is working correctly to check if one of the two radio buttons checked prior to allowing submit to complete. However, I have a 2nd button which performs a 'redirect' which I can't figure out how to include on that JS validation process to echo 'error3' if neither radio button not checked prior to the defined redirect for that button. Can someone advise how I can include the 'ddsumbit' button to to that JS validation script to ensure one of the radio buttons are checked before redirecting to link? The code is below - thx! <script type="text/javascript"> // script.js handle the form submit event on form (below) entitled form.html function prepareEventHandlers() { document.getElementById("form3").onsubmit = function() { if ((document.getElementById("func_0").checked == true) || (document.getElementById("func_1").checked == true)) { document.getElementById("error3").innerHTML = ""; // to STOP the form from submitting return true; // uncomment this line to have submit working //return false; // remove line when using in the real world } else { // reset and allow the form to submit document.getElementById("error3").innerHTML = "A SELECTION IS REQUIRED"; return false; } }; } // when the document loads window.onload = function() { prepareEventHandlers(); }; </script> Here's the radio buttons & the two buttons code that is defined within the form: <form action="index.php" method="post" name="form3" id="form3"> <span id="error3"></span> <input type="radio" name="func" value="work" id="func_0" /> <input type="radio" name="func" value="nonwork" id="func_1" /> <input type="submit" name="submit3" id="submit3" value="next>" tabindex="15" /> <input type="button" name="ddsubmit" id="ddsumbit" onClick="location.href='cancel.php'" value="decline" tabindex="20" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/249218-confirm-radio-button-selected-before-redirect/ 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.