I have this form:
<form action = "" method = "post">
<input type = "text" name = "tbox_phone" placeholder = "phone" onkeyup="checker_phone(this.value)">
<div id = "msg"></div>
<input type = "submit" name = "button_submit" value = "submit">
</form>
The checker_phone is connected to a JavaScript that runs through another PHP page.
The script:
<script>
function checker_phone(val)
{
$.ajax ({
type:"POST",
url:"check_phone.php",
data:'phone='+val,
success: function(data){
$("#msg").html(data);
}
});
}
</script>
The PHP page:
$phone = htmlentities($_POST['tbox_phone']);
$var_phone= mysqli_real_escape_string($connect,$phone);
$search= "SELECT * FROM users WHERE phone= '$var_phone' ";
$exec= mysqli_query($connect,$search);
$count = mysqli_num_rows($exec);
if($count==1) {
echo "that phone number is already registered";
}
The above code worked. Now I want to disable the submit button whenever the result from the php's count returns 1. Is there any way I could this?
Javascript is good, but I prefer simple ones, rather than long and complicated scripts.
$('input[name=button_submit]').prop('disabled',data == "that phone number is already registered")