slj90 Posted February 6, 2015 Share Posted February 6, 2015 I'm trying to stop my form from submitting whilst it checks the login details. <script> function loginbuttonFunction(){ var tl=$("#username"); var tp=$("#password"); $.post('../action/logincheck.php',{user:tl.val(), password:tp.val()},function(l){ if(l=='correct') { $('#loginform').submit(); } else if(l=='locked') { $('#locked').show(); return false; } else if(l=='incorrect') { $('#incorrect').show(); return false; } }); } </script> However, it's not working. It's submitting the form on any outcome. I've tried using: $(document).ready(function() { $("#loginform").submit(function(e){ e.preventDefault(e); }); }); Which works on stopping the form submitting but when the details are correct it still doesn't submit the form!Please help, Thanks, Quote Link to comment Share on other sites More sharing options...
Solution requinix Posted February 6, 2015 Solution Share Posted February 6, 2015 Use your first bit of code but make the login button be a plain button (eg, type=button) instead of a submit button. Quote Link to comment Share on other sites More sharing options...
slj90 Posted February 6, 2015 Author Share Posted February 6, 2015 Thanks for your reply.I solved it by adding $("#loginform").unbind('submit'); if(l=='correct') { $("#loginform").unbind('submit'); $('#loginform').submit(); } 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.