Is there a way to force a user to select an autocomplete value before they can submit the form?

Posted by Randy Johnson on Stack Overflow See other posts from Stack Overflow or by Randy Johnson
Published on 2010-05-31T15:39:56Z Indexed on 2010/05/31 15:43 UTC
Read the original article Hit count: 251

I am using the jqueryui autocomplete feature to allow the user to select their location. I need to make sure they select a location from the autocomplete before they can submit the form. I don't want them to be able to submit the form before they select a value.

My solution is after they submit make sure that the value found is in the database. The other solution would be that when they click submit or after they leave the location box and go to another field to submit the entry via ajax to ensure it is valid if not show an error and do not let them submit the form.

I was wondering if there was something easier I could do, or if there is something more elegant. I realize they have to be able to type something into the box to get the autocomplete to work, so I could force them to select a value from the autocomplete because it is not a select box, so it seems that my above solutions would be the best way to go.

Thoughts?

© Stack Overflow or respective owner

Related posts about jquery-ui

Related posts about jquery-ajax