toolman Posted March 5, 2015 Share Posted March 5, 2015 Hi,I have the following code which checks email addresses are valid. I want to remove the "Nice!..." part if the email address is ok and just have the form submit. How can I do this? $(document).ready(function(e) { $('#email-submit').click(function() { var sEmail = $('#email').val(); // checking empty fields if (validateEmail(sEmail)) { alert('Nice!! your Email is valid, now you can continue..'); } else { alert('Invalid Email Address'); e.preventDefault(); } }); }); Also, I have noticed if the email address is invalid, the alert works, but then goes to a page with the form on - like an external page. The form action is linking to an external URL as the action is hosted externally. Is there a way I can stop the form submitting when the email is invalid?Hope than makes sense.Thanks! Link to comment https://forums.phpfreaks.com/topic/295127-validate-on-else-statement-only-and-not-if-and-else/ Share on other sites More sharing options...
requinix Posted March 5, 2015 Share Posted March 5, 2015 I want to remove the "Nice!..." part if the email address is ok and just have the form submit. How can I do this?By removing that part. Literally. Not sure why you didn't consider that. Also, I have noticed if the email address is invalid, the alert works, but then goes to a page with the form on - like an external page. The form action is linking to an external URL as the action is hosted externally. Is there a way I can stop the form submitting when the email is invalid? e.preventDefault();is what would have done the job if e was the event for the button click and not from the document.onready. So $(document).ready(function() { $('#email-submit').click(function(e) {And really, this code should be executing on the form submission, not on the button click. $(document).ready(function() { $('some selector for your form').submit(function(e) { Link to comment https://forums.phpfreaks.com/topic/295127-validate-on-else-statement-only-and-not-if-and-else/#findComment-1507690 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.