Hello is there an easy way to autopopulate select boxes like this http://remysharp.com/2007/01/20/auto-populating-select-boxes-using-jquery-ajax/ but using prototype? Thank you --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
$(document).observe("dom:loaded", function(){ $("ctlJob").observe("change", function(){ new Ajax.Request("/select.php", { postBody: $H({id: $(this).val(), ajax: ''true''}).toQueryString(), onSuccess: function(res){ var j = res.responseText.toJSON(), options = ''''; for (var i = 0; i < j.length; i++) { options += ''<option value="'' + j[i].optionValue + ''">'' + j[i].optionDisplay + ''</option>''; } $("ctlPerson").update(options); } }) }) }) No guarantees (I pasted the jQuery version into an editor and hacked it up ;)) but that''s the gist of it. -Fred On Thu, May 29, 2008 at 12:30 PM, Chris <haroldthehungry-ee4meeAH724@public.gmane.org> wrote:> > Hello is there an easy way to autopopulate select boxes like this > > http://remysharp.com/2007/01/20/auto-populating-select-boxes-using-jquery-ajax/ > but using prototype? > Thank you > > >-- Science answers questions; philosophy questions answers. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Oops, forgot one thing. $(document).observe("dom:loaded", function(){ $("ctlJob").observe("change", function(){ new Ajax.Request("/select.php", { postBody: $H({id: *$F(this)*, ajax: ''true''}).toQueryString(), onSuccess: function(res){ var j = res.responseText.toJSON(), options = ''''; for (var i = 0; i < j.length; i++) { options += ''<option value="'' + j[i].optionValue + ''">'' + j[i].optionDisplay + ''</option>''; } $("ctlPerson").update(options); } }) }) }) On Thu, May 29, 2008 at 1:13 PM, Frederick Polgardy <fred-SMQUYeM9IBBWk0Htik3J/w@public.gmane.org> wrote:> No guarantees (I pasted the jQuery version into an editor and hacked it up > ;)) but that''s the gist of it. > > -Fred > > > On Thu, May 29, 2008 at 12:30 PM, Chris <haroldthehungry-ee4meeAH724@public.gmane.org> wrote: > >> >> Hello is there an easy way to autopopulate select boxes like this >> >> http://remysharp.com/2007/01/20/auto-populating-select-boxes-using-jquery-ajax/ >> but using prototype? >> Thank you > >-- Science answers questions; philosophy questions answers. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
#inject seems to be quite helpful in this case: $("ctlJob").observe("change", function() { new Ajax.Request("/select.php", { parameters: { id: $F(this), ajax: true }, onSuccess: function(resp) { var json = resp.responseText.toJSON(); var output = json.inject('''', function(output, option) { return output + ''<option value="#{optionValue}">#{optionDisplay}</option>''.interpolate(option); }) $("ctlPerson").update(output); } }) }); - kangax On May 29, 2:17 pm, "Frederick Polgardy" <f...-SMQUYeM9IBBWk0Htik3J/w@public.gmane.org> wrote:> Oops, forgot one thing. > > $(document).observe("dom:loaded", function(){ > $("ctlJob").observe("change", function(){ > new Ajax.Request("/select.php", { > postBody: $H({id: *$F(this)*, ajax: ''true''}).toQueryString(), > onSuccess: function(res){ > var j = res.responseText.toJSON(), options = ''''; > for (var i = 0; i < j.length; i++) { > options += ''<option value="'' + j[i].optionValue + ''">'' + > j[i].optionDisplay + ''</option>''; > } > $("ctlPerson").update(options); > } > }) > }) > > }) > > On Thu, May 29, 2008 at 1:13 PM, Frederick Polgardy <f...-SMQUYeM9IBBWk0Htik3J/w@public.gmane.org> > wrote: > > > > > No guarantees (I pasted the jQuery version into an editor and hacked it up > > ;)) but that''s the gist of it. > > > -Fred > > > On Thu, May 29, 2008 at 12:30 PM, Chris <haroldthehun...-ee4meeAH724@public.gmane.org> wrote: > > >> Hello is there an easy way to autopopulate select boxes like this > > >>http://remysharp.com/2007/01/20/auto-populating-select-boxes-using-jq... > >> but using prototype? > >> Thank you > > -- > Science answers questions; philosophy questions answers.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---