Do I need to create another javascript to populate descriptions?  I'm
stuck... please help!


On May 5, 7:49 am, KT <[email protected]> wrote:
> Thanks and sure thing:
>
> javascripts controller:
>
>   def dynamic_products
>     @products = Product.find(:all)
>   end
>
> -------------------------------------------------------------------------------------------------------------
> dynamic_products.js.erb:
>
> var products = new Array();
> <% for product in @products -%>
>   products.push(new Array(<%= product.category_id %>, '<%=h
> product.name %>', <%= product.id %>));
> <% end -%>
>
> function categorySelected() {
>   category_id = $('request_category_id').getValue();
>   options = $('request_product_id').options;
>   options.length = 1;
>   products.each(function(product) {
>     if (product[0] == category_id) {
>       options[options.length] = new Option(product[1], product[2]);
>     }
>   });
>   if (options.length == 1) {
>     $('product_field').hide();
>   } else {
>     $('product_field').show();
>   }
>
> }
>
> document.observe('dom:loaded', function() {
>   categorySelected();
>   $('request_category_id').observe('change', categorySelected);
>
> });
>
> --------------------------------------------------------------------------------------------------------------------------------
> view:
>
> <p>
>   <b><label for="request_category_id">Select Category:<font
> color="red">*</font></b></label><br>
>   <%= select( "request", "category_id", Category.find( :all, :order =>
> "name" ).collect { |c| [c.name, c.id] }, { :include_blank =>
> true, :order => "name" })%>
> </p>
>
> <div>
> <p id="product_field">
>   <b><label for="request_product_id">Select Product/Service:<font
> color="red">*</font></b><br></label>
>   <%= select( "request", "product_id", Product.find( :all, :order =>
> "name" ).collect { |p| [p.name, p.id] }, { :include_blank =>
> true, :order => "name" })%>
>
> -----------------------------------------------------------------------------------------------------------------------------------
> On May 4, 7:55 pm, "[email protected]" <[email protected]> wrote:
>
>
>
> > Can you show the code in the corresponding views and controllers?
>
> > On May 4, 2:30 pm, KT <[email protected]> wrote:
>
> > > I've implemented Ryan Bates's Dynamic Select modules as done 
> > > here:http://railscasts.com/episodes/88-dynamic-select-menus
>
> > > I have a Category select (hardware, software, media...)
> > > Based on the Category, I have a Product select (if hardware is chosen,
> > > then PC, Monitor, Printer...)
>
> > > That all works.
>
> > > But now I would like to show the product.description below the
> > > selected Product.
>
> > > HELP!??!?!
>
> > > Thanks for any input.....
>
> > > --
> > > You received this message because you are subscribed to the Google Groups 
> > > "Ruby on Rails: Talk" 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 
> > > athttp://groups.google.com/group/rubyonrails-talk?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Ruby on Rails: Talk" 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 
> > athttp://groups.google.com/group/rubyonrails-talk?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" 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 
> athttp://groups.google.com/group/rubyonrails-talk?hl=en.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" 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-talk?hl=en.

Reply via email to