CMellor Posted January 9, 2007 Share Posted January 9, 2007 Hello,I am stuck, as I am in the need for a very simple way to validate e-mail address' when a form has been submitted. My form is using AJAX to submit the form, and when a field is missed out, an alert() appears with the error. Here is my code for reference:[code]function sendAppForm() { // Error checking // Display Name if(document.app_form.display_name.value == "") { alert("Please choose a superstar!"); document.app_form.display_name.focus(); return; } if(document.app_form.display_name.value.length < 3 || document.app_form.display_name.value.length > 32) { alert("Your selected superstar has a too short or long name"); document.app_form.display_name.focus(); return; } // Username if(document.app_form.username.value == "") { alert("Please choose a username"); document.app_form.username.focus(); return; } if(document.app_form.username.value.length < 3 || document.app_form.username.value.length > 32) { alert("Your selected username has a too short or long name"); document.app_form.username.focus(); return; } // Password if(document.app_form.password.value == "") { alert("Please choose a password"); document.app_form.password.focus(); return; } if(document.app_form.password.value.length < 3 || document.app_form.password.value.length > 32) { alert("Your selected password has a too short or long name"); document.app_form.password.focus(); return; } // E-Mail // Role Play if(document.app_form.roleplay.value == "") { alert("You MUST provide a Role Play!"); return; } ajax.open('POST', 'ajax/send_app.php'); ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); ajax.onreadystatechange = function() { if(ajax.readyState == 4 && ajax.status == 200) { document.getElementById("appForm").innerHTML = ajax.responseText; } }; ajax.send('superstar='+document.app_form.display_name.value);}[/code]I've tried a few bits of code, and they do actually validate the e-mail when it's not inserted correctly, but when it is and I try to submit the form, well it just won't submit.Any help would be greatly appreciated!Thanks!Chris. Quote Link to comment Share on other sites More sharing options...
fenway Posted January 10, 2007 Share Posted January 10, 2007 You're probably missing a return true; at thend. 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.