2

I am trying to get my form to submit when a user either clicks enter or mouse clicks. I have seen some examples as well as the example on the jQuery UI site. The example that I am following is jQuery UI autocomplete submit onclick result. Therefore my code looks like this.

<script type="text/javascript"> $(document).ready(function() { $("#myInput").autocomplete({ source: "fh_autocomplete_search.php", minLength: 2, select: function(event, ui) { if(ui.item){ $("#myInput").value(ui.item.value); } $("#myInput").submit(); } }); $( "#myInput" ).bind( "autocompleteselect", function(event, ui) { }) }); </script> 

I'm not sure what should go under the .bind section of the code. Or really what it is even doing. And I have been here and read it but still just not clicking http://api.jquery.com/bind/ When I put an alert under it and select a ui.item from the #myInput box the alert does go off. But nothing fills or submits. If I put an alert under the if(ui.item) part it doesn't go off. If someone could explain to me what is going on and suggest some code to put under the .bind section I would greatly appreciate it.

2 Answers 2

4

If the id of the form is myForm:

$(document).ready(function() { $("#myInput").autocomplete({ source: "fh_autocomplete_search.php", minLength: 2, select: function(event, ui) { $("#myInput").val(ui.item.value); $("#myForm").submit(); } }); }); 

Also see this example.

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

1 Comment

wait so i dont need .bind autocompleselect ? so i altered my code like you instructed but now it doesn't pick up the item on mouse selecting. thanks for the help
1

I'm not entirely sure you need to write code for the "autocompleteselect" event. The default behavior of the event is to replace the text in the textbox with the users selection from the menu of items.

2 Comments

any idea why it doesn't work when i use the mouse to select? nothing additional ends up in the text box it just sends whatever i had already typed.
I think you might want to move that submit() inside your if.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.