Friday, May 06, 2011

jQuery autoselect

Today I wanted to use the jQuery autoselect feature to add an autoselect to an input field on a web page.  I have heard alot about jQuery but until yesterday I really hadn't done anything with it. (how horrible is that)  Yesterday I used it for the simple task of updating a text field with the value of a select dropdown field. Simple, this is all it took:

$("#jid").change(function(){
   $("#city").val($("#jid option:selected").text());
});

Where jid is the select dropdown and city is the text input I wanted the text from the dropdown to be copied to.

The autocomplete was a little more complicated, but not much.  I use the following as the basis for this project and pretty much just copied it and adapted it to my site:

http://www.coldfusionjedi.com/index.cfm/2010/4/12/Playing-with-jQuery-UIs-Autocomplete-Control

jQuery does make things easy.  I use a cfc as in the 2nd to last example on above to return dynamic results. 

No comments: