input not detected in jquery
Will not fire code not sure why, i have done .change .on('input') every
thing i can find, its most likely simple and deserves a facepalm lol.
$(function () {
alert('hie');
//the min chars for username
var min_chars = 3;
//result texts
var characters_error = 'Minimum amount of chars is 3';
var checking_html = 'Checking...';
//when button is clicked
$('#myusername').bind("change paste keyup",function () {
//run the character number check
if ($('#myusername').val().length < min_chars) {
//if it's bellow the minimum show characters_error text
$('#username_availability_result').html(characters_error);
$('#checkuser').show(fast);alert('hsdi');
}
else {
//else show the cheking_text and run the function to check
$('#username_availability_result').html(checking_html);
$('#checkuser').show(fast);
check_availability();alert('hi');
}
});
});
//function to check username availability
function check_availability(){
//get the username
var username = $('#myusername').val();
//use ajax to run the check
$.post("../php/checkuser.php", { username: username },
function(result){
//if the result is 1
if(result == 1){
//show that the username is available
$('#username_availability_result').html(username + ' is
Available');
}else{
//show that the username is NOT available
$('#username_availability_result').html(username + ' is
not Available');
}
});
}
HTML
<tr>
<td>Username</td>
<td><input type="text" name="username" placeholder="Username"
id="myusername"></td>
</tr>
<tr id="checkuser" style="display: none">
<td>
</td>
</tr>
No comments:
Post a Comment