satheshf12000 Posted May 12, 2009 Share Posted May 12, 2009 How would you make the JS mainFunction() stop? Bcos through AJAX, I call a PHP - MSSQL storedProc (executing the proc and php is not a problem here, proc is returning values i.e. 0 to 10 and I can get it with the responseText) and if it returns something I don't want, say if storedProc returns 0, I wound want to stop the mainFunction() from executing further. And the form should proceed only if the StoredProc returns 1 or any other values. Issues: [*]I have an alert message which doesn't even pop up if the mainFunction() doesn't have this statement at the end: return false; [*]And the return false within the if ( responseMsg == 0 ) doesn't seem to stop the mainFunction Can you guys pls help with this? Many thanks.. I have something like this: /* JavaScript function */ function mainFunction() { /* a few form checking code and the AJAX request code goes here */ http.onreadystatechange = function() { if(http.readyState == 4 && http.status == 200) { var responseMsg = http.responseText; if ( responseMsg == 0 ) { alert ("check submission return code was zero"); return false; } else if ( responseMsg == 1 ) { alert ("check submission return code was one"); return false; } } } } And the HTML Code will look like this: <input type="submit" value="Submit" name="preSubmissionFinished" onclick="return mainFunction()"> Quote Link to comment https://forums.phpfreaks.com/topic/157757-solved-ajax-work-fine-how-to-stop-form-from-submitting-with-regard-to-responsetext/ Share on other sites More sharing options...
satheshf12000 Posted May 13, 2009 Author Share Posted May 13, 2009 It's solved. The problem was with the button. <input type="button"> works. Such a silly mistake :-\ Quote Link to comment https://forums.phpfreaks.com/topic/157757-solved-ajax-work-fine-how-to-stop-form-from-submitting-with-regard-to-responsetext/#findComment-833007 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.