Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 739
  • Last Modified:

jquery autocomplete - clear form field upon no results

Hi,
Hopefully an easy one this.

I am using the jQuery autocomplete plugin to connect to a coldfusion cfc and return database information.
If the database returns results and the user selects the value this then populates form fields for subsequent submission BUT if the user then amends the search and enters text with no results the 'jetId' field retains the original select value as not results were found and of course no select happened.

Can anyone suggest a way of clearing the jetId field upon no results being returned?

Regards
Leigh
$(function() {
$("#jets").autocomplete({
source: httpPath+"assets/publicComps/autoComplete.cfc?method=jets&returnformat=json",
select:function(event,ui) {$("#jetId").val(ui.item.id)}
});
});

Open in new window

0
Lmillard
Asked:
Lmillard
1 Solution
 
BardobraveCommented:
How about cleaning jetId values on jets keystrokes?

$("#jets").keypress(function () {
  $("#jetId").val('');
});

This way you ensure the jetId value will be always empty until a selection over the autocomplete is made.
0
 
LmillardAuthor Commented:
worked perfectly thank you!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now