Hello guys, probably I am doing something wrong since I don't know a lot about javascript,
for me the change event is working fine, when I get an option from the list, and then I modify part of the selected option and click anywhere on the page, the change event gets triggered , but in my case I have an anchor which is submitting a form, the change event don't get triggered when clicking on the link, so previos seleted itemValue is sent within the request, code looks something like this
- <script>
$(function() {
$("#autocomplete").autocomplete({
source: "search.do",
select: function(e, ui) {
e.preventDefault(); // <--- Prevent the value from being inserted.
$("#itemLabel").val(ui.item.label);
$("#itemId").val(ui.item.value);
},
change: function(e, ui) {
if (!ui.item) {
$("#itemId").val('');
}
}
});
});
function submitSearchByGroup() {
if ($.trim($('#itemId').val()) !== "")
{
document.searchForm.submit();
} else {
alert("Invalid entry");
}
}
- <form method="post" name="searchForm" action="Search" >
- .....
- <a href="javascript:submitSearch();" class="actionButton"
I have tried a few things but none of them worked , do you know if there's a work around ?
Thanks in advance