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"))+"'...