Hello Everybody I need help to making code I have form and I want to send data to php page by Ajax but if JavaScript enable submit Form using JavaScript code if JavaScript disable submit form using standard submit form And i have tried making this code but I failed to do so and This is the code created by HTML <form action="page.php" method="post" onsubmit="return login()"> User Name <input type="text" name="user" id="user" /> <br/>Password <input type="password" name="pass" id="pass" /> <br/><br/> <input type="submit" name="login" id="login" value="Login" onclick="" /> </form> <br /><br /> <div id="result"></div> Code (markup): JavaScript / Ajax function login(){ var user = document.getElementById('user').value; var pass = document.getElementById('pass').value; Http.onreadystatechange = function(){ if (Http.readyState == 4) { document.getElementById('result').innerHTML = Http.responseText; } else { document.getElementById('result').innerHTML = "Loading"; } } url = "user=" + user + "&pass=" + pass; Http.open("post", "page.php", true); Http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); Http.send(url); } Code (markup): PHP $user = $_POST['user']; $pass = $_POST['pass']; if($user == "ahmed" && $pass == "123"){ echo "Right"; } else{ echo "Wrong"; } PHP: Please Help Me
Thank You Mr Unni krishnan For Help I think there are easy other ways. Used ( return True or False ), I want this way Thank you again
You can't put Ajax in a form onsubmit like that. http://www.alistapart.com/articles/userproofingajax/
you must return false at the end of the login function or the form will submit anyway, if this doesn't work try calling the login function from the onclick event of the submit button (once again you will still need to return false).