Results 1 to 3 of 3
  1. #1
    anny123 is offline Member
    Join Date
    Nov 2011
    Posts
    9
    Rep Power
    0

    Default need help in ajax enabled auto complete feature

    hello all am new to jsp servlet as well as ajax.i have written a code for the auto complete feature and
    getting the correct output but my problem is that its not in proper format.

    The code is as follows:
    sample.jsp coding :-

    <script language="javascript" type="text/javascript">
    function showData(value)
    {
    xmlHttp=GetXmlHttpObject()
    var url="servlet/getAutoSuggestData";
    url=url+"?country="+value;
    xmlHttp.onreadystatechange=stateChanged
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
    }
    function stateChanged()
    {
    if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
    System.out.println(xmlHttp.responseText);
    var showdata = xmlHttp.responseText;
    document.getElementById("mydiv").innerHTML= showdata;
    //document.getElementById("country").value= showdata;

    }
    }
    function GetXmlHttpObject(){
    var xmlHttp=null;
    try {
    xmlHttp=new XMLHttpRequest();
    }
    catch (e) {
    try {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    out.println(e);
    }
    catch (e) {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    out.println(e);
    }
    }
    return xmlHttp;
    }

    </script>

    input field :-
    <input id="country" type="text" name="country" onkeyup="showData(this.value)"><br/>
    <div id="mydiv">
    </div>

    I am retrieving the data from database in Vector.
    My problem is I am not getting the data exactly below the text box such that I can select the field.
    how do i proceed ? plz guide..Thanks .
    Last edited by anny123; 11-19-2011 at 11:41 AM.

  2. #2
    rushtong is offline Member
    Join Date
    Aug 2011
    Posts
    1
    Rep Power
    0

    Default Re: need help in ajax enabled auto complete feature

    I would recommend using a framework instead of rolling your own. the jQuery UI autocomplete feature will handle the positioning and provides a way to display the data coming from different formats. For instance, your servlet could send back streaming text, json, jsonp, etc. and jquery will handle it for you. I do this quite a bit and it's worked great for our web apps: jQuery UI - Autocomplete Demos & Documentation

  3. #3
    anny123 is offline Member
    Join Date
    Nov 2011
    Posts
    9
    Rep Power
    0

    Default Re: need help in ajax enabled auto complete feature

    thanks finally am using the same.:)

Similar Threads

  1. Auto Complete - Please Assit
    By chellede in forum New To Java
    Replies: 1
    Last Post: 01-29-2010, 07:02 PM
  2. Eclipse auto-complete lists duplicate methods
    By Red Hunt in forum Eclipse
    Replies: 1
    Last Post: 12-10-2009, 10:53 AM
  3. auto complete textarea
    By praba@spiretek.in in forum AWT / Swing
    Replies: 0
    Last Post: 11-16-2009, 07:06 AM
  4. Auto-complete/Auto-fix for custom statement
    By dark_cybernetics in forum Eclipse
    Replies: 0
    Last Post: 08-19-2008, 11:19 AM
  5. [SOLVED] Auto complete Text.
    By smartsubroto in forum New To Java
    Replies: 9
    Last Post: 06-27-2008, 04:05 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •