Ajax call php function in controller

I am using the below jquery code to call an ajax function in my CS checker. Search is the name of the function. As always, the function is called in the controller. But I have to get the value in the page textbox inside this function. This is mainly an auto-completion feature. on the key the function is called. But I cannot get the value in the textbox to do the relavent search. answer me whatever you think is useful to me. Thank you 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


source to share


1 answer


You need to associate autocomplete with the input field:

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

});

      

If you enter your own ID in the input field, 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();

});

      

+2


source







All Articles