jimleeder123 Posted October 26, 2015 Share Posted October 26, 2015 I've got this code, returns true if the date format entered in a field is correct, or false if its wrong. Code below. $(function(){ //when form is submitted, check the date entered $('#submit').click(function( e ){ checkDate(); }); }) I want to stop the form from submitting but can't get it to work. I've tried putting "e.preventDefault();" under the checkDate function (which works fine itself) but doesn't work. I've tried an if statement but couldn't get it to work. Basically if the function returns false then it shouldn't submit (but does when you click submit currently) Please note I'm a JavaScript novice, got the function online. Quote Link to comment https://forums.phpfreaks.com/topic/298834-stop-submit-if-function-returns-false/ Share on other sites More sharing options...
Solution benanamen Posted October 26, 2015 Solution Share Posted October 26, 2015 (edited) You might want to just use a date-picker that will put the date format you want into a read only field. Dont allow the user to enter it wrong in the first place. Edited October 26, 2015 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/298834-stop-submit-if-function-returns-false/#findComment-1524361 Share on other sites More sharing options...
jimleeder123 Posted October 26, 2015 Author Share Posted October 26, 2015 The problem with that is the HTML5 date field is not possible with all browsers, unless you'd do that with JavaScript? Quote Link to comment https://forums.phpfreaks.com/topic/298834-stop-submit-if-function-returns-false/#findComment-1524362 Share on other sites More sharing options...
benanamen Posted October 26, 2015 Share Posted October 26, 2015 (edited) I didn't say anything about a "date field". I said read only which would be a standard text input and then use the date picker to populate it. Edited October 26, 2015 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/298834-stop-submit-if-function-returns-false/#findComment-1524364 Share on other sites More sharing options...
jimleeder123 Posted October 26, 2015 Author Share Posted October 26, 2015 I've found this jQuery date picker, works ok - https://jqueryui.com/datepicker/ Quote Link to comment https://forums.phpfreaks.com/topic/298834-stop-submit-if-function-returns-false/#findComment-1524365 Share on other sites More sharing options...
benanamen Posted October 26, 2015 Share Posted October 26, 2015 There are many out there. Just set the input to read only so the user cannot edit the date by hand and you are all set. Quote Link to comment https://forums.phpfreaks.com/topic/298834-stop-submit-if-function-returns-false/#findComment-1524366 Share on other sites More sharing options...
jimleeder123 Posted October 26, 2015 Author Share Posted October 26, 2015 Ok have done, thanks a lot for your help! Quote Link to comment https://forums.phpfreaks.com/topic/298834-stop-submit-if-function-returns-false/#findComment-1524368 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.