views:

40

answers:

2

As a follow on my from last post - http://stackoverflow.com/questions/3307520 . 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 to 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?

A: 

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.

Stephen
+1  A: 

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

Check my answer on your other question: http://stackoverflow.com/questions/3317685

dejavu
Cheers for the answer, I will try it on Monday (just so you know I haven't disappeared, and will green-tick when I get it working!)
Stephen