Check Username Exists or not in jsp.through jquery.


put the textfield id="docid"


$(document).ready(function(e) {
   $("#docid").keyup(function (e) {

//removes spaces from username
$(this).val($(this).val().replace(/\s/g, ''));

var username = $(this).val();
//if(username.length < 4){$("#user-result").html('');return;}

//if(username.length >= 4){
$("#user-result").html('<img src="ajax-loader.gif" />');
$.post('check_username.php', {'username':username}, function(data) {
 $("#user-result").html(data);
});
//}
});
});


check_username.jsp


<%
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305","root","root");
PreparedStatement pst=con.PreparedStatement("select * from demo where id='"+Integer.parseInt(request.getParameter("username"))+"'");
ResultSet rs=pst.executeQuery();
if(rs.next())
{
out.println("UserName already exists");
}
else
{
out.println("true");
}
%>


Popular posts from this blog

Simple Sign up design. Android.

Cart page design in android.

Set Date on jDateChooser and retrieve record from database.