I have a big problem that I've been trying to solve for over a few hours now.
I need to make an auto-check login availability option in my site's registration form. I want it to check the input value after an user leaves the input field (blur). Here is the important part of my HTML:
<div id="wrapper">
<div id="register_area">
<p id="register_description">Registration form.</p>
<form action="security/check_register.php" method="post">
<div id="register_form">
<input type="text" name="login" placeholder="Login" id="input_login"/>
<input type="password" name="password" placeholder="Password" id="input_password"/> <br />
<input type="password" name="password2" placeholder="Re-type password"/> <br />
<input type="text" name="mail" placeholder="E-mail"/> <br />
<input type="text" name="birth_year" placeholder="Birth year (YYYY)"/> <br />
<input type="submit" value="Register"/>
<p></p>
</div>
</form>
</div>
</div>
Here's my script:
$("#input_login").blur(function() {
jQuery.ajax({
url: "security/find_login.php",
data:'login='+$("#input_login").val(),
type: "POST",
success:function(data){
if (data) {
$("#input_login").value = "";
$("#input_login").style = "border: 2px solid red;"
}
},
error:function (){}
});
});
My security/find_login.php script just checks if the username already exists in database, if so it returns 1, if no, it returns 0. (This part works well)
So, the problem is... After an ajax call, my find_login.php script returns correct value, but my input field (id="input_login) doesn't change it's border and value. In fact, if I try to change anything, nothing happens. I think that after an ajax call my jQuery script can't see any element on my site. What am I doing wrong?
I found similar problem: jQuery doesn't work after content is loaded via AJAX But I don't know how to apply this idea to my script. I tried almost everything. Please, tell me what to do. Show me how to change my script so that it would work.
Thanks in advance!