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, Link to comment https://forums.phpfreaks.com/topic/294423-prevent-form-from-submitting/ Share on other sites More sharing options...
requinix Posted February 6, 2015 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. Link to comment https://forums.phpfreaks.com/topic/294423-prevent-form-from-submitting/#findComment-1505055 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(); } Link to comment https://forums.phpfreaks.com/topic/294423-prevent-form-from-submitting/#findComment-1505056 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.