0

Jquery autocomplete in not working for input text box

following is my javascript code

 <script type="text/javascript" src="js/jquery.js"></script>
 <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
 <script type="text/javascript" src="js/jquery.jcarousel.min.js"></script>
 <script type="text/javascript" src="js/jquery.cycle.all.min.js"></script>
 <script type="text/javascript" src="js/serverSideValidation.js"></script>
 <script type="text/javascript" src="js/clientSideValidation.js"></script>
 <script type="text/javascript" src="js/jquery.ui.autocomplete.min.js"></script>

 <script type="text/javascript">

 $(document).ready(
function() {
    $('#slideshow').cycle({
        fx : 'fade',
        speed : 'slow',
        timeout : 5000,
        pager : '#slider_nav',
        pagerAnchorBuilder : function(idx, slide) {
            // return sel string for existing anchor
            return '#slider_nav li:eq(' + (idx) + ') a';
        }
    });

    addSearchHelp();
});

function addSearchHelp() {
    var availableTags = [ "ActionScript", "AppleScript", "Asp", "BASIC",
            "C", "C++", "Clojure", "COBOL", "ColdFusion", "Erlang",
            "Fortran", "Groovy", "Haskell", "Java", "JavaScript", "Lisp",
            "Perl", "PHP", "Python", "Ruby", "Scala", "Scheme" ];
    $("input#searchBox")[0].autocomplete({source:availableTags, minLength: 2});
}

and folllowing is my input text box

<input name="searchBox" id="searchBox" type="text" class="input-header" 
style="background-image:url(images/search-bg.png); background-repeat:repeat-x; 
background-position:center; height:31px; width:423px" size="65" maxlength="60" 
 onblur="this.value=Trim(this.value)" onkeypress="return checkenter(event,'product')" 
  />

please suggest answer to my problem

2 Answers 2

2

Try this way,

Script

    $(document).ready(function() {
        $('#slideshow').cycle({
            fx : 'fade',
            speed : 'slow',
            timeout : 5000,
            pager : '#slider_nav',
            pagerAnchorBuilder : function(idx, slide) {
                // return sel string for existing anchor
                return '#slider_nav li:eq(' + (idx) + ') a';
            }
        });

        $('#searchBox').on('keyup', function(event){
            addSearchHelp();
        });

    });

    function addSearchHelp() {
        var availableTags = [ "ActionScript", "AppleScript", "Asp", "BASIC",
                "C", "C++", "Clojure", "COBOL", "ColdFusion", "Erlang",
                "Fortran", "Groovy", "Haskell", "Java", "JavaScript", "Lisp",
                "Perl", "PHP", "Python", "Ruby", "Scala", "Scheme" ];
        $("input#searchBox").autocomplete({source:availableTags, minLength: 2});
    }

HTML

<input name="searchBox" id="searchBox" type="text" class="input-header" size="65" maxlength="60" onblur="this.value=Trim(this.value)" onkeypress="return checkenter(event,'product')" />

Hope this will help you.

Sign up to request clarification or add additional context in comments.

3 Comments

Now it is throwing following exception uncaught typeerror object # object has no method 'on'............Is it someproblem with my loading of jquery files ??
What is the jQuery version you are using? try $('#searchBox').bind('keyup',.... or $('#searchBox').keyup(function(){......});. This will work.
...i was using older version of jquery ... thanks for your suggestion
0

Try:

$("input#searchBox").autocomplete({source:availableTags, minLength: 2});

You're trying to apply .autocomplete to a DOM object, not to the jQuery object it expects.

2 Comments

also directly use IDs of the html element for maximum performance. Hence $("#searchBox") instead of $("input#searchBox")..
I have changed it $("#searchBox").autocomplete({source:availableTags, minLength: 2}); Now it is throwing following exception uncaught typeerror object # object has no method 'autocomplete'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.