I am having a code that will check if the username is available in the database, the code can show an error message that the email is already exists but when I press the submit button it will insert the username in the database even if the username is already exists.
here is my code:
function validateForm(){
<script>
$(document).ready(function () {
$("#Name").change(function () {
var username = $("#Name").val();
var msg = $("#msg");
if (username.length > 2) {
$("#msg").html('Checking availability');
$.ajax({
type: "POST",
url: "check_availability.php",
data: "Name=" + username,
success: function (messagess) {
$("#msg").ajaxComplete(function (event, request) {
if (messagess.indexOf('OK') > 0) {
$("#Name").removeClass("exists");
$("#Name").addClass("avail");
msg.html('the user name is available</font>');
} else {
$("#Name").removeClass("avail");
$("#Name").addClass("exists");
msg.html('the user name is already exists');
}
});
}
});
}
});
});
}
</script>
</head>
<body>
<form action="" method="post" name="form" onsubmit="return validateForm()">
User Email:
<input type="text" name="Name" id="Name" value="" />
<span id="msg"></span>
</form>
</body>
</html>