FastPHP Posted May 3, 2010 Share Posted May 3, 2010 I have absolutely no idea why this isn't working. Here's the PHP file: //Check if there is a get variable if(isset($_GET['username'])) { $username = $_GET['username']; //Get string length $length = strlen($username); //Check length if ($length < 8 && $length > 3) print true; else print false; } Here's the jQuery: $(document).ready(function(){ // Declare click variable var u_click = false; //If username focused, funciton: $("#username").focus(function() { //If not clicked yet, function: if (u_click == false) { //Set clicked to true and clear field u_click = true; $("#username").val(""); } }); //Username check for length function $("#username").keyup(function() { //Send variable $.get("../php/checkuser.php", {username: $("#username").val()}, function (data) { if (data == true) { $("#usernameMessage").innerHTML = "Right"; } else { $("#usernameMessage").innerHTML = "Wrong"; } }); }); }); This first jQuery function meant to clear the form works 100%, but the other doesn't return anything at all in the span with ID "usernameMessage". Why is this...any help? Thanks! Oh, and hi! XD Quote Link to comment https://forums.phpfreaks.com/topic/200612-phpjquery-form-error/ Share on other sites More sharing options...
Ken2k7 Posted May 3, 2010 Share Posted May 3, 2010 You sure you got the path "../php/checkuser.php" correct? Also, data is a string, not a boolean. Quote Link to comment https://forums.phpfreaks.com/topic/200612-phpjquery-form-error/#findComment-1052727 Share on other sites More sharing options...
FastPHP Posted May 3, 2010 Author Share Posted May 3, 2010 Yes, I have checked multiple times on the path. Thanks for the suggestion though. And what do you mean?? Edit: modified and still didn't work. New PHP: //Check length if ($length < 8 && $length > 3) print "true"; else print "false"; New jQuery: if (data == "true") Quote Link to comment https://forums.phpfreaks.com/topic/200612-phpjquery-form-error/#findComment-1052728 Share on other sites More sharing options...
Ken2k7 Posted May 3, 2010 Share Posted May 3, 2010 I mean in the success function of your $.get request, the variable data is of type string, but you're comparing it to a boolean value. "true" != true. o.O Quote Link to comment https://forums.phpfreaks.com/topic/200612-phpjquery-form-error/#findComment-1052731 Share on other sites More sharing options...
FastPHP Posted May 3, 2010 Author Share Posted May 3, 2010 I changed it to a string, still doesn't work (read above)? Ahh! Quote Link to comment https://forums.phpfreaks.com/topic/200612-phpjquery-form-error/#findComment-1052732 Share on other sites More sharing options...
Ken2k7 Posted May 3, 2010 Share Posted May 3, 2010 Do you have the site up? Mind providing the link? Quote Link to comment https://forums.phpfreaks.com/topic/200612-phpjquery-form-error/#findComment-1052735 Share on other sites More sharing options...
FastPHP Posted May 3, 2010 Author Share Posted May 3, 2010 Gah, no. It's local at the moment, and good thing, too. But here's the HTML, jQuery, and PHP (cropped). HTML: <label>Desired Username:</label> <input id="username" type="text" name="username" /> <span id="usernameMessage"></span> <br /> <div id="spacer"></div> jQuery: $(document).ready(function(){ // Declare click variable var u_click = false; //If username focused, funciton: $("#username").focus(function() { //If not clicked yet, function: if (u_click == false) { //Set clicked to true and clear field u_click = true; $("#username").val(""); } }); //Username check for length function $("#username").keyup(function() { //Send variable $.get("../php/checkuser.php", {username: $("#username").val()}, function (data) { if (data == "true") { $("#usernameMessage").innerHTML = "Right"; } else { $("#usernameMessage").innerHTML = "Wrong"; } }); }); }); <?php //Check if there is a get variable if(isset($_GET['username'])) { $username = $_GET['username']; //Get string length $length = strlen($username); //Check length if ($length < 8 && $length > 3) print "true"; else print "false"; } ?> I think it might be $("#usernameMessage").innerHTML = "Right"; because I've had problems with innerHTML before. Not sure... Quote Link to comment https://forums.phpfreaks.com/topic/200612-phpjquery-form-error/#findComment-1052737 Share on other sites More sharing options...
Ken2k7 Posted May 4, 2010 Share Posted May 4, 2010 Oh right. Stupid me. $("#username").text("Right"); For html, $("#username").html("Right"); Quote Link to comment https://forums.phpfreaks.com/topic/200612-phpjquery-form-error/#findComment-1052746 Share on other sites More sharing options...
FastPHP Posted May 4, 2010 Author Share Posted May 4, 2010 I have done exactly what you said...still nothing. Sorry! Quote Link to comment https://forums.phpfreaks.com/topic/200612-phpjquery-form-error/#findComment-1052760 Share on other sites More sharing options...
Ken2k7 Posted May 4, 2010 Share Posted May 4, 2010 #usernameMessage, not #username. Typo. Did you not catch that? Quote Link to comment https://forums.phpfreaks.com/topic/200612-phpjquery-form-error/#findComment-1052761 Share on other sites More sharing options...
FastPHP Posted May 4, 2010 Author Share Posted May 4, 2010 #usernameMessage, not #username. Typo. Did you not catch that? Yeah, I did. Here's my new code. jQuery: $(document).ready(function(){ // Declare click variable var u_click = false; //If username focused, funciton: $("#username").focus(function() { //If not clicked yet, function: if (u_click == false) { //Set clicked to true and clear field u_click = true; $("#username").val(""); } }); //Username check for length function $("#username").keyup(function() { //Send variable $.get("../php/checkuser.php", {username: $("#username").val()}, function (data) { if (data == true) { $("#usernameMessage").html("Right"); } else { $("#usernameMessage").html("Wrong"); } }); }); }); PHP: <?php //Check if there is a get variable if(isset($_GET['username'])) { $username = $_GET['username']; //Get string length $length = strlen($username); //Check length if ($length < 8 && $length > 3) echo true; else echo false; } ?> Note: I tried with both boolean and string. Quote Link to comment https://forums.phpfreaks.com/topic/200612-phpjquery-form-error/#findComment-1052771 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.