Ok so, Im using jQuery to do username and email checks before a signup...
this sets a variable true or false depending on the response from php.
$(document).ready(function() {
if (usr_checked == true) {
if (em_checked == true) {
$("#registerbttn").removeAttr("disabled");
}
}
else {
$("#registerbttn").attr("disabled", "disabled");
}
});
How exactly do i get it to watch those variables live?
Thanks :D The Code below is one of the sets of code that sets the functions
pic1 = new Image(16, 16);
pic1.src = "loader.gif";
$(document).ready(function(){
$("#username").change(function() {
var usr = $("#username").val();
if(usr.length >= 3)
{
$("#unstatus").html('<img src="loader.gif" align="absmiddle"> Checking availability...');
$.ajax({
type: "POST",
url: "check.php",
data: "username="+ usr,
success: function(msg){
$("#unstatus").ajaxComplete(function(event, request, settings){
if(msg == 'OK')
{
$("#username").removeClass('object_error'); // if necessary
$("#username").addClass("object_ok");
$(this).html(' <img src="accepted.png" align="absmiddle"> <font color="Green"> Available </font> ');
$("#registerbttn").removeAttr("disabled");
var usr_checked = true;
}
else
{
$("#username").removeClass('object_ok'); // if necessary
$("#username").addClass("object_error");
$("#registerbttn").attr("disabled", "disabled");
$(this).html(msg);
var usr_checked = false;
}
});
}
});
}
else
{
$("#status").html('<font color="red">The username should have at least <strong>3</strong> characters.</font>');
$("#username").removeClass('object_ok'); // if necessary
$("#username").addClass("object_error");
$("#registerbttn").attr("disabled", "disabled");
var usr_checked = false;
}
});
});
See Question&Answers more detail:os