i have a web form with user registration, what i want to do is to find the entered username is exist in the database, if exit don't submit the form. I used the code below, the problem is even if the username is exist the form will submit the value, if alter i can see the error showing but when i cancel the alter message box it will submit the form. please help me......... function emailCheck() { str=document.forms['recruiter'].username.value; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("username").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","lib/validate_email_user.php?username="+str,true); xmlhttp.send(); } Code (markup):
Javascript is user side, you can't check the existing username in database with JS but This could be solve with server side code, what server side code You already use?
with the help of php and ajax i can display the validation failure that is the username is exist in the database, the problem is even after displaying the error when is i press the submit button it will submit data in to database....
You need to add it to the 'onblur' handler of the textbox for the username.... not the 'submit' event of the form...