jquery autocomplete - clear textbox if there is no value RRS feed

  • Question

  • Hi All,

    i created textbox which works on autocomplete function based on data from another list. I need to clear the textbox if the user has not selected any item or he has entered wrong text. below is my code

                url: "http://address/_vti_bin/lists.asmx",
                type: "POST",
                dataType: "xml",
                data: soapEnv,
                contentType: "text/xml; charset=\"utf-8\"",
                success: function (xmlResponse) {
                    var domElementArray = $("z\\:row", xmlResponse);
                    var dataMap = domElementArray.map(function () {
                        return {
                            value: $(this).attr('ows_AirportCode'),
                            id: $(this).attr('ows_AirportCode')
                    var data = dataMap.get();

                    //Find the Sharepoint Portal Search Box (this is a poor selector, but it is not properly named by sharepoint, well it is but INamingContainer getrs in the way)   
                    $("input[title='AirportCode Required Field']").autocomplete(
                    source: data,
                    miniLength: 3,
                    response: function (event, ui) {
                        // ui.content is the array that's about to be sent to the response callback.
                        if (ui.content.length == 0) {
                            $("#empty-message").text("No results found");
                        } else {
            }); //.ajax  


    Sunday, February 7, 2016 8:10 PM


  • Hi,

    A suggestion is that, you can bind an event handler to the “focusout” event to check the input value and clear the textbox accordingly.


    Best regards,


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    • Proposed as answer by Dennis Guo Thursday, February 25, 2016 3:00 AM
    • Marked as answer by Dennis Guo Friday, February 26, 2016 8:23 AM
    Tuesday, February 9, 2016 7:55 AM