I’m using the Jquery Autocomplete combobox util in my web application (really nice tool) but I’d like to prevent a form submission if the field associated with the autocomplete combobox is empty.
So for now, if nothing has been selected via the combobox I just don’t display the submit button, but if something has been selected and then erased… I don’t when (or where) I’ve got to hide my submit button.
Any ideas?
Thanks in advance.
Edit here is my code:
/* HTML */
//The select filled with data for the combobox
<select id="combobox">
<option value=""></option>
<c:forEach var="item" items="${itemList}">
<option value="${item.value}">${item.key}</option>
</c:forEach>
</select>
//The form with the button
<form name="updateForm" action="update.htm" method="post">
<input type="hidden" id="id1" name="cID" />
<input type="hidden" id="id2" name="rID" />
<input type="submit" id='btn_update' value="Update" />
</form>
/* JAVASCRIPT */
//combobox widget init (...)
$("#btn_update").hide();
$( "#combobox" ).combobox({
selected:selectedFunc
});
If I did not understand wrong, you are looking something like this,
html
script
and here is jsFiddle link
EDIT:
Couldn’t solve your problem exactly, but maybe this example will show to you the way
you can use change event to control autocomplete, so if it’s null, hide submit button, if not null show submit button.
here is an example in jsFiddle
but bad news from jquery-ui-autocomplete document
meaning is that will not work onkeypress, it must be blurred to be triggered. if you can add keypress event to jquery-ui-autocomplate that will work exactly.