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

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

jquery autocomplete - clear form field upon no results

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?

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

Open in new window

1 Solution
How about cleaning jetId values on jets keystrokes?

$("#jets").keypress(function () {

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

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