bindiya Posted December 29, 2010 Share Posted December 29, 2010 I have used jquery/ajax to check for username availability.it works fine.But how to write the code to make the username field blank ,if the username exist? my js/ajax code is as follows $(document).ready(function() { //var name=$('#username').val(); $("#username").blur(function() { //remove all the class add the messagebox classes and start fading $("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow"); //check the username exists or not from ajax $.post("user_availability.php",{ user_name:$(this).val() } ,function(data) { if(data=='no') //if username not avaiable { $("#msgbox").fadeTo(200,0.1,function() //s'This User name Already exists'tart fading the messagebox { //add message and change the class of the box and start fading $(this).html("already exist").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 fadingUsername available to register' $(this).html("Proceed").addClass('messageboxok').fadeTo(900,1); }); } }); }); }); Quote Link to comment https://forums.phpfreaks.com/topic/222875-i-need-to-make-a-username-field-blank-after-checking/ Share on other sites More sharing options...
Adam Posted December 29, 2010 Share Posted December 29, 2010 $('#username').val(''); Edit: you may also want to add focus back to the input, which you can with: $('#username').val('').focus(); Quote Link to comment https://forums.phpfreaks.com/topic/222875-i-need-to-make-a-username-field-blank-after-checking/#findComment-1152533 Share on other sites More sharing options...
bindiya Posted January 3, 2011 Author Share Posted January 3, 2011 where will i put this code? Quote Link to comment https://forums.phpfreaks.com/topic/222875-i-need-to-make-a-username-field-blank-after-checking/#findComment-1154098 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.