Q:

refresh text box when a particular value is matched

I have a text box in index.jsp and after writing something i am calling a jsp by jquery. But my requirement is if a particular value will be matched in server side then how can i auto refresh that text box? It means suppose i entered apple then by onkeyup event i am sending the name(apple) to check.jsp and in this jsp page, I have kept apple in a string. So now an alert will come in index.jsp that apple already exists and simulatenously that text box will be auto refreshed. How can i do it? I am a beginner to this field.
index.jsp
<script type="text/javascript">
  $(document).ready(function() {
    $("#textbox").keyup(function () {
        $.getJSON('check.jsp', {
            textboxname: this.value
        });
    });
  }); 
</script>

inside body
<input type="text" id="textbox" name="textboxname"/>

check.jsp
String textboxname=request.getParameter("textboxname");

A:

on keyup send the value to the server and if it matches return true or false, then in the success handler check what is returned if its true refresh and not do something
$("#textbox").keyup(function () {
        $.getJSON('check.jsp', {
            textboxname: this.value
        },function(data){
          if(data.isTrue){
              alert("the value already exists");
              $("#textbox").val(''); //clear the text box                                  
         }
          else
              //do something                 
         });
    });
}); 

on the server not the exact servlet code but you'll get the idea
JSONObject match = new JSONObject();

 //if value matches 
     match.put("isTrue","true");
 else
    match.put("isTrue","false");
response.setContentType("application/json");
response.getWriter().write(match.toString());true

