views:

121

answers:

1

I am using the below jquery code to call a ajax function in my contorller CS. Search is the function name. How ever the function is called in the controller. But i am supposed to get a value in the text box of the page inside this function. Basically this is for the auto complete feature. on key up the function is called. But i am not able to get the value in the textbox to do a relavent search. please reply back anything you feel would be helpful to me. Thanks in advance.

$(document).ready(function(){
    $("#searchusers").autocomplete("http://localhost/CS/index.php/search" , {
     width: 500,
     selectFirst: false
    });

});
$(document).ready(function(){
    $("#searchusers").result(function(event, data, formatted) {
     if (data)
      $(this).parent().next().find("input").val(data[1]);
    });
    $('#set1 *').tooltip();
    $('#firstname').tooltip();

});
+2  A: 

You need to bind autocomplete to the input box:

$(document).ready(function(){
    $("#searchusers").parent().next().find("input").autocomplete("http://localhost/CS/index.php/search" , {
        width: 500,
        selectFirst: false
    });

});

If you give the input box its own id, the code becomes much clearer:

<input type="text" id="searchUsersInput">

Then:

$(document).ready(function(){
    $("#searchUsersInput").autocomplete("http://localhost/CS/index.php/search" , {
        width: 500,
        selectFirst: false
    });

});
$(document).ready(function(){
    $("#searchUsersInput").result(function(event, data, formatted) {
        if (data)
                $(this).val(data[1]);
    });
    $('#set1 *').tooltip();
    $('#firstname').tooltip();

});
Greg