thefortrees Posted August 7, 2007 Share Posted August 7, 2007 Hi all - I am having a problem with the onsubmit event handler. Onsubmit, I call the function below. The problems I am having are: 1) If the confirm dialog is used, the redirect does not occur. 2) If the alert dialog is used, even though the function returns false after the dialog, the form still submits! I have been wrestling with this for a while now. Thanks for your help. function enterInfo() { if (validate() == 1) { if (confirm("Would you like to enter our monthly prize drawing? (OK = Yes, Cancel = No)")) { window.location = "enter_info.php"; return true; } else { window.location = "thank_you.php"; return true; } } else if (validate() == -1) { alert('Please respond to all questions.'); return false; } } Link to comment https://forums.phpfreaks.com/topic/63734-onsubmit-help/ Share on other sites More sharing options...
xenophobia Posted August 8, 2007 Share Posted August 8, 2007 How you call your enterInfo() function? You should use this: <form onsubmit="return enterInfo();"> So if your function return false, the form will not submit, else it does. Link to comment https://forums.phpfreaks.com/topic/63734-onsubmit-help/#findComment-318547 Share on other sites More sharing options...
php_tom Posted August 8, 2007 Share Posted August 8, 2007 How you call your enterInfo() function? You should use this: <form onsubmit="return enterInfo();"> So if your function return false, the form will not submit, else it does. I don't think that will help. Where is the onsubmit event going to return to? There's no caller on the call stack... I would do it in PHP. Make the file your JS code is in have some thing like: <?php if(one of the POST data == "") {// They didn't respond to a question... echo "You didn't respond to all of the questions. Click the back button in your browser and finish filling out the form."; exit; } else { // Process the POST data from the form here, then echo "Would you like to enter our monthly prize drawing? "; echo "<a href='enter_info.php'>Yes</a> <a href='thank_you.php'>No</a> } ?> This also has the advantage of browsers without JS can still use it. Link to comment https://forums.phpfreaks.com/topic/63734-onsubmit-help/#findComment-318598 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.