Jquery autocomplete no result append as dropdown child issue

I have a website (cpusort.com) made in ASP.Net MVC3, where user can search using jquery ui autocomplete and select from found resutls.

I am using this script for the resutls

        $(function () {
            function log(message) {
                source: "/Search/",
                minLength: 1,
                response: function (event, ui) {
                    if (ui.content.length === 0) {
                        alert("No Result Found");
//.append("<a href='/AdvancedSearch/[search_term]'>More results for [search_term]</a>")
                open: function (event, ui) {
                    var url = "<a href='/AdvancedSearch/[search_term]'>More results for [search_term]</a>";
                select: function (event, ui) {
                    return false;
    .data("ui-autocomplete")._renderItem = function (ul, item) {
        return $("<li>")
        .append("<a href='/Cpu/" + item.query + "'><div style='width:100%'><span class='titlesearch' >" + item.title + "</span></div><div <div style='width:100%'><span class='titlesmallspan'>" + item.clockspeed + " GHz | " + item.cores + "</span></div></a>")

But how can I show If there is No result found, and in this case i am using alert, how can I append a single child with text "Search in Advance"

.append("<a href='/AdvancedSearch/[search_term]'>More results for [search_term]</a>")

Please help figure this out, Thanks


I would suggest you to make use of open event of jQuery auto-complete

open: function (event, ui) {
      search_term = event.target.value;
      var d = $('.ui-autocomplete').append("<a href='/AdvancedSearch/[" + search_term + "]'>More results for [" + search_term + "]</a>")


This is will append the html elements that you need at end of the options listed in the auto-complete.


Hope you can understand.


From your comments, it seems you tried by appending which won't work for open event of auto-complete.

Instead you should go for response event of auto-complete.


1) open event is triggered when a matching is found and it won't work when the match is not found.

2) whereas response event does triggered in both the cases(this can't be used for you case#1) but it much helpful only for your case#2.

response: function (event, ui) {
            if (ui.content.length === 0) {  //check for none results
                search_term = event.target.value;
                $(this).next('a').remove(); //Remove before you add
                $(this).after("<a href='/AdvancedSearch/[" + search_term + "]'>More results for [" + search_term + "]</a>");


Well this makes sense, I think so.

Modified the code to re-create something equal to your question.

Need Your Help

Unix Shell script to monitor a folder for files with user details

shell unix

I have below requirement where I want to monitor a folder for file activity and user who is doing that.

Split main class into different files

objective-c xcode

I just finished my first application for Mac, and now works fine. The application has a main class of NSObject. This class has become huge, because I have many for loops and if-else statements. Since