View Single Post
  #4  
Old 02-04-2014, 04:21 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 91,115
Kyttias is on a distinguished road
Default

Ok, well, on my test (unrelated to Mysidia):
Code:
<script>
 window.initQueue.push(function(){
	 $("#regusername").focus(function() {
	 $("label[for=regusername]").addClass('error').removeClass('success').removeClass('valid').text('');	 
	 });
	 $("#regusername").focusout(function() {
		 $("label[for=regusername]").addClass('error').removeClass('success').removeClass('valid').text('');	 
	 });
	$("#regusername").focusin(function() {
		$("#message").text("").css({'display' : 'none'});
	});
    $("#regusername").change(function(){
	$("#message").html("Checking...");
	var username=$("#regusername").val();
	 $.ajax({
		type:"post",
		url:"./assets/php/check.php",
		data:"username="+username,
		success:function(data){
			if(data==0){ $("#message").text("Username available!").css({'display' : 'none', 'color' : 'green', 'font-size' : '.8em', 'padding' : '2px 8px', 'margin-top' : '2px'}); }
			else{ $("#message").text("Username already taken!").css({'display' : 'inline-block', 'color' : 'red', 'font-size' : '.8em', 'padding' : '2px 8px', 'margin-top' : '2px'});
				  $("label[for=regusername]").addClass('error').removeClass('success').removeClass('valid').text('');}
			}
		});
	});
});
</script>
I'm using ajax there to push the result from my check.php (which I'd have to reconfigure to work with Mysidia, how do you have yours set up? Save me some some thinking?):
Code:
<?
 
  mysql_connect("127.0.0.1","root","");
  mysql_select_db("test");
 
  $username=$_POST["username"];
  $query=mysql_query("SELECT * from users where Username='$username' ");
 
  $find=mysql_num_rows($query);
 
  echo $find;
 
?>
I'd definitely read up on $.ajax?

You can safely ignore all the adding and removing of success/valid/error classes I did (because I was combining it with another system that also checked for minimum/maximum length requirements... and that passwords had a number, matched, and emails had an @). I was using the same span for both types of confirmation of success and if one was true but not the other, the whole span needed to be red. (ie: Yeah, it fits the minimum requirements for length, but it's taken so it needs to be red and throw and error, not have the green success check.)

Last edited by Kyttias; 02-04-2014 at 04:36 PM.
Reply With Quote