I would then be able to tie in this from your code:
Code:
var ret=function(flag){if(flag=='f'){return false;}if(flag=='t'){return true;}}
function x(flag){document.getElementById('next2').style.disabled=(ret(flag)==true)?'disabled':'';}
When I enter the username, then the password, it enables the submit button (even though it says "Username not available"). when i do it the other way around, it does not enable it. here is my code:
Code:
<input type="text" name="username" id="username" style="height:40px; font-size:18px;"
onkeydown='javascript: $("#usernameDiv").html("Please wait...");
$.get
(
"checkUser.php",
{
cmd: "check", username: $("#username").val()
},
function(data){
$("#usernameDiv").html(data);
// this will enable the button
if(data=="Username available!"){ $("#next2").attr("","disabled"); }
}
)
.error(function() { alert("There was an error. Please try again. If this persists to happen, please contact us."); });'
onblur='javascript: $("#usernameDiv").html("Please wait...");
$.get
(
"checkUser.php",
{
cmd: "check", username: $("#username").val()
},
function(data){
$("#usernameDiv").html(data);
// this will enable the button
if(data=="Username available!"){ $("#next2").attr("","disabled"); }
}
)
.error(function() { alert("There was an error. Please try again. If this persists to happen, please contact us."); });' />
here is working example http://ilolo.ru/wd/checkuser/. John, Steve and Mark are already taken by users. it is not a good idea to check the input on key events because it will work for every typed symbol that's why it's assigned on blur in my page.
PHP Code:
<?php
// usernames array (you get it from the DB with SELECT)
$usernames = array('John','Steve','Mark');
$username = $_GET['username'];
$output='';
if($_GET['cmd'] == 'check'){
//if(!isUserID($user)){$output.='Invalid User ID'; echo $output; return;}
if((empty($username)) || (strlen($username) < 4)){$output.='<b style="color:Darkorange">Please enter 5 characters or more</b>'; echo $output; return;}
//$rs_duplicate = mysql_query("select count(*) as total from members where username='$username' ") or die();
//$num_rows = mysql_num_rows($rs_duplicate);
//if($num_rows > 0){$output.='Username not available'; echo $output; return;}
if(in_array($username, $usernames)){$output.='<b style="color:Crimson">Username is already taken!</b>'; echo $output; return;}
else{$output.='<b style="color:Green">Username available!</b>'; echo $output;}
}
?>
man! the php-part must be in a separate php-file named checkUser.php! take a look at the javascript at $.get("checkUser.php",{cmd: "check", username: $("#username")......
use [code]YOUR CODE GOES HERE[/code] or burn in Hell
yea; i did have that file. i believe i had two different variable names running around ($username and $user). thanks for your time thought; i appreciate it!
Bookmarks