Jump to content

Recommended Posts

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!  :D

 

Oh, and hi! XD

Link to comment
https://forums.phpfreaks.com/topic/200612-phpjquery-form-error/
Share on other sites

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")

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...

#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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.