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 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 lies in this event of the code is that I have problems
if(response=="OK")
{
$('#ResetSubmit').attr('disabled','');
return true;
}
else
{
$('#ResetSubmit').attr('disabled','disabled');
return false;
}
I perfectly manage to disable my submit button but if the event is true I can't disable it.
You can use
$('#ResetSubmit').removeAttr("disabled");
to remove the attributedisabled
from your input, the opposite of this function is to add the attribute:$().attr();
You can also use
promp
it to toggle between its states, which would be the most viable way when the response is true or false:Activate:
Deactivate: