Hi, I'm making a validation form onblur, but I wanna do it on a popup box.
When I try the js code in a normal form it works perfectly, but when I try to implement it into a popup box form it doesn't work then.
I'd like to know if in a popup I must write any other codelines.
This is my HTML for a normal form:
PHP Code:
<form action="asda.php" name="customForm" id="customForm" method="post" enctype="multipart/form-data">
<div class="both">
<br clear="all" />
<div>
<label>Country</label>
<input id="User_Nick" name="User_Nick" type="text" value="" onblur="return check_username();" />
<div id="Info"></div>
<span id="Loading"><img src="loader.gif" alt="" /></span>
</div>
</div>
<br clear="all" />
</form>
And this is my code from the popup box form:
PHP Code:
<div id="popupContact">
<a id="popupContactClose">x</a>
<h1>User Registration</h1>
<p id="contactArea">
<form action="asda.php" name="customForm" id="customForm" method="post" enctype="multipart/form-data">
<div class="both">
<br clear="all" />
<div>
<input id="User_Nick" name="User_Nick" type="text" value="" placeholder="Nickname" maxlength="20" onblur="return check_username();">
<div id="Info"></div>
<span id="Loading"><img src="loader.gif" alt="" /></span>
</div>
</div>
<br clear="all" />
</form>
</p>
</div>
onblur only works in the first form. Any idea about why this happens?
Thank you in advance.
EDIT: I don't know if you need, cause it works but I will post here the code.js
Code:
//The document has the focus
$(document).ready(function() {
$('#Loading').hide();
});
// Check Username
function check_username(){
var username = $("#User_Nick").val();
$('#Loading').show();
$.post("check_username_availablity.php", {
username: $('#User_Nick').val(),
}, function(response){
$('#Info').fadeOut();
$('#Loading').hide();
setTimeout("finishAjax('Info', '"+escape(response)+"')", 450);
});
return false;
}
//Finish Ajax Function
function finishAjax(id, response){
$('#'+id).html(unescape(response));
$('#'+id).fadeIn(1000);
}
And my PHP CODE
PHP Code:
<?php
$link=mysql_connect('localhost','root',''); //Conexión a la base de datos.
mysql_select_db("supahsonic", $link); //Selección de la base de datos.
if($_REQUEST){
$username = $_REQUEST['username'];
if(strlen($username)>2){
$query = "select * from users where user_nick = '".strtolower($username)."'";
$results = mysql_query( $query) or die('ok');
if(mysql_num_rows(@$results) > 0) // not available
{
echo '<div id="Error">Already Taken</div>';
}
else
{
echo '<div id="Success">Available</div>';
}
}else{
if(strlen($username)==0){
echo '<div id="Error">The field cannot be blank</div>';
}else{
echo '<div id="Error">Nick name too short</div>';
}
}
}?>