On Apr 23, 2014, at 9:02 AM, Werner Laude wrote: > > Am 23.04.2014 um 14:54 schrieb Walter Lee Davis <wa...@wdstudio.com>: > >> >> >> One thing to remember, conceptually, is that you cannot replace the >> "innards" of a select as if they were HTML without destroying its ability to >> react correctly to scripting or user input. The only "bulletproof" way to >> update the contents of a select is to set its options collection length to >> 0, then iterate over your collection of data, using the new >> Option(text,value) constructor to build each option. Doing it any other way >> will end in tears. This has nothing to do with CoffeeScript or JavaScript >> and everything to do with browsers and the DOM. >> >> Walter >> > > > Thanks Walter.. > > may be you have some code to demonstrate..so I get the idea ?
Sure. This is using Prototype.js for clarity, you'll have to guess (I don't know) how to describe it in jQuery, if that's your thing. <select name="foo" id="foo" size="1"> <option value="1">One</option> <option value="2">Two</option> <option value="3">Three</option> <option value="4">Four</option> </select> var new_options = [{"value": "5", "text": "Five"}, {"value": "6", "text": "Six"}]; var foo = $('foo'); foo.options.length = 0; new_options.each(function(opt){ foo.options[foo.options.length] = new Option(opt['text'], opt['value']); }); Walter > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-talk+unsubscr...@googlegroups.com. > To post to this group, send email to rubyonrails-talk@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/rubyonrails-talk/C108F5F1-049F-4CE4-858A-01B4E5D3AE2A%40googlemail.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/973207C0-B497-413A-A5A2-E8226C09FEDB%40wdstudio.com. For more options, visit https://groups.google.com/d/optout.