0
I need the button
is enabled when the email does not exist in the database. Note that the validation if the email already exists works, I need the implementation to enable the button if the email does not exist.
Javascript
<script type="text/javascript">
$(document).ready(function () {
$('#email').blur(function() {
$th = $(this);
$.ajax({
url: 'plano.php',
type: 'POST',
data: {email: $th.val()},
beforeSend: function(){
$("#resultados").html("Carregando...");
},
success: function(data){
$("#resultados").html(data);
},
error: function(){
$("#resultados").html("Ouve um erro ao enviar sua URL");
}
});//ajax
});
});
</script>
HTML
<div id="resultados"></div>
<button id="registrar" disabled="disabled" type="submit">CONTRATAR AGORA!</button>
plano.php
$email = $_POST['email'];
#Conecta banco de dados
$sql = mysqli_query($con, "SELECT email FROM conta WHERE email = '$email' ORDER BY EMAIL ASC LIMIT 1");
while($sqlregistro=mysqli_fetch_array($sql))
{
$emailbanco = $sqlregistro['email'];
}
echo $emailbanco;
echo "<br>";
if(isset($email ) && $emailbanco === $email ){
echo "Este email existe no banco";
}else{
echo "Email digitado " .$emailbanco. " Nao existe no banco ";
}
It worked in part, let me explain what happened. When I type an email that actually exists the code keeps the button disabled. And when I enter an email that doesn’t exist it enables the button. Perfect!!! However, when I type an email that does not exist and then I write another one that exists it does not disable, and keeps enabled. The correct one would be that each time I left the email field it enabled or disabled the button.
– Gladison
Do it like this... In the Blur, before the line
$th = $(this);
, place$("#registrar" ).prop( "disabled", true );
. Or make a$('#email').keyup(()=>{$("#registrar" ).prop( "disabled", true );})
that there will always disable and will only enable when rolling the Success in Ajax. :)– thxmxx
Unfortunately it did not give
– Gladison
Put to disable in keyup?
– thxmxx
yes, I did. but it didn’t work.
– Gladison
How to do to exist the email deletes what is in the email input?
– Gladison
The keyup is out of the Blur, right? Weird...
– thxmxx
Let’s go continue this discussion in chat.
– Gladison