#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" <[EMAIL PROTECTED]> 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 <[EMAIL PROTECTED]>
> 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 <[EMAIL PROTECTED]> 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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to