Help with email validation Ajax + php

0

I have the following code;

function checkemail()
{
 var email=document.getElementById( "emailReg" ).value;

 if(email)
 {
  $.ajax({
  type: 'post',
  url: 'check_email.php',
  data: {
   user_email:email,
  },
  success: function (response) {
   $( '#confirmUsername' ).html(response);
   if(response=="OK")   
   {
    $('#ResetSubmit').attr('disabled','');
    return true;    
   }
   else
   {
    $('#ResetSubmit').attr('disabled','disabled');
    return false;   
   }
  }
  });
 }
 else
 {
  $( '#confirmUsername' ).html("");

  return false;
 }
}

with this function I can check in an event onkeyup() in the input of my form

<input type="email" class="form-control" name="emailReg" id="emailReg" onkeyup="checkemail()" ?>"required>

With which I can correctly validate whether or not the mail to be checked exists, my problem currently resides in this code event is that I have problems

if(response=="OK")   
   {
    $('#ResetSubmit').attr('disabled','');
    return true;    
   }
   else
   {
    $('#ResetSubmit').attr('disabled','disabled');
    return false;   
   }

Achieve perfectly disable my submit button but if the event is true I can not disable it.

    
asked by Alexander Quiroz 04.02.2018 в 03:13
source

1 answer

1

You can use $('#ResetSubmit').removeAttr("disabled"); to eliminate the attribute disabled of your input, the opposite of this function is to add the attribute: $().attr();

You can also use promp to make toggle between its states that would be the most viable way when true or false the response:

Activate:

$("#ResetSubmit").prop("disabled", false);

Deactivate:

$("#ResetSubmit").prop("disabled", true);
    
answered by 04.02.2018 / 04:19
source