Jump to content

Multi-Checker


manalnor

Recommended Posts

Hello friends,

 

I've tried to search over the Internet but didn't found any tutorial how to do the following :-

 

let say we have form with input username and input email just 2 field

 

HTML Code

 

<form>
<table>
<tr>
<td>Username :</td>
<td><input id="username" size="20" type="text" name="username"></td>
</tr> 
<tr>
<td>Email :</td>
<td><input id="email" size="20" type="text" name="email"></td>
</tr>
</table> 
</form>

 

 

As you can see no submit button cause we will only check out if username and/or email is not stored already, by using ajax

 

My problem : i can only check out for username (1 field) but i can not check for 2 fields or more and i want to know how to apply it for 2 fields (username and email)

 

Here is my idea for only one field (username)

 

I'll add in the HTML code  this

 

<td><div id="status"></div></td>

 

and will add this java code

 

<SCRIPT type="text/javascript">
pic1 = new Image(16, 16);
pic1.src = "loader.gif";
$(document).ready(function(){
$("#username").change(function() {
var usr = $("#username").val();
if(usr.length >= 4)
{
$("#status").html('<img src="loader.gif" align="absmiddle"> Checking availability...');
$.ajax({
type: "POST",
url: "check.php",
data: "username="+ usr,
success: function(msg){
$("#status").ajaxComplete(function(event, request, settings){
if(msg == 'OK')
{
$("#username").removeClass('object_error');
$("#username").addClass("object_ok");
$(this).html(' <img src="tick.gif" align="absmiddle">');
}
else
{
$("#username").removeClass('object_ok');
$("#username").addClass("object_error");
$(this).html(msg);
}
});
}
});
}
else
{
$("#status").html('<font color="red">The username should have at least <strong>4</strong> characters.</font>');
$("#username").removeClass('object_ok');
$("#username").addClass("object_error");
}
});
});
</SCRIPT>

 

Explain : it will get the input of username and will send it to check.php

 

Now check.php code (should have all usernames that will compare with it)

 

<?php
if(isSet($_POST['username']))
{
$usernames = array('john','michael','terry', 'steve', 'donald');
$username = $_POST['username'];
if(in_array($username, $usernames))
{
echo '<font color="red">The username<STRONG>'.$username.'</STRONG> is already in use.</font>';
}
else
{
echo 'OK';
}
}
?>

 

Now it is very clear , if will automatic check the username

 

now my problem is how to apply it for also email

Link to comment
Share on other sites

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.