开发者

How to make jQuery autocomplete execute a search() when user hits submit

As a follow on my from last post - How would I trim the input to a JQuery auto-complete box? . I decided to make a new question rather than to continue editing that one.

I currently have jQuery ui autocomplete 1.8 (or so) working reasonably well, except from one thing. If the user just enters a (valid) name and hits submit, the auto-complete lookup never runs, and so the associated value is never grapped and assigned to the input box. This, of course, is a problem. Reading the documentation, it implies that I could use the jQuery search() method to over-come this. However, I am struggling to get it to work. I have tried both putting the call t开发者_C百科o search() in the onblur event of the text input, and in the onclick event of the submit button, but to no avail - whenever I hit submit I have no value for the input box. The code:

<form action = "<?php echo $this->URL();?>" method="post">
    <fieldset>
        <ol>
            <li>
                <label for="Resource">Resource</label>
                <input id="Resource" name="Resource" class="text" type="text"  value="" onblur="jQuery('#Resource').search();"/>
            </li>
        </ol>
    </fieldset>
    <fieldset class="submit">
        <input id="Submit" name="Submit" type="Submit" class="Submit" value ="Submit" onclick = "jQuery('#Resource').search();"/>
    </fieldset> 
</form>

So, what exactly am I doing wrong?


You need to add the automated-choose-any-matching-result code in the change event.

Check my answer on your other question: jQuery autocomplete problem - doesn't match if user doesn't specifically select


I have both answered my own question, and also discovered that search() doesn't work like I thought. I tried:

    <input id="Submit" name="Submit" type="Submit" class="Submit" value ="Submit" onclick="jQuery('#Resource').autocomplete('search');"/>

And discovered that a second before the form finishes submitting, the auto-complete box flashes up. Obviously search() just makes the auto-complete box do a normal search, not an automated-choose-any-matching-result search, which is what I was looking for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜