Help finding out cause of misbehaving function
Sorry to bother everyone again. For some reason when I try to run the following with validateusername() nothing happens.
<script language="javascript">
//<----------------------------------+
// Developed by Roshan B开发者_StackOverflow中文版hattarai and modified by Harry Rickards
// Visit http://roshanbh.com.np for the origional version of this script and more.
// This notice MUST stay intact for legal use
// -------------------------->
function validateusername()
{
$("#username").blur(function()
{
//remove all the class add the messagebox classes and start fading
$("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn(1000);
//check the username exists or not from ajax
$.post("usernamecheck.php",{ username:$(this).val() } ,function(data)
{
if(data=='no') //if username not avaiable
{
$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
{
//add message and change the class of the box and start fading
$(this).html('This User name Already exists').addClass('messageboxerror').fadeTo(900,1);
});
}
else
{
$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
{
//add message and change the class of the box and start fading
$(this).html('Username available to register').addClass('messageboxok').fadeTo(900,1);
});
}
});
});
}
</script>
It's probably a simple mistake, but would somebody be able to point me in the right direction?
Thanks
The code have no syntax errors, but as you use event binding, have you tried to run it on page load? I believe you don't see results because corresponding input doesn't run your function on desired event.
$().ready(function(){
validateusername();
});
Also, use <script type="text/javascript">
, language
is deprecated.
Have you tried to display the values while it is running? Also, using a Javascript debugger also typically helps.
精彩评论