Chris Bartlett wrote:
> I've just been doing something similar. This works, but might not be
> as Railsy as it could be:
> 
> <h3>Number of Tickets?</h3>
> <%= select :tickets, :quantity, {"1" => "1", "2" => "2"}, {:prompt =>
> 'Select quantity...'}, {:onchange => "if(this.options
> [this.selectedIndex].value=='2')
>   {Effect.BlindDown('guest_name', {duration: 0.5}); return false;}
>      else
>   {Effect.BlindUp('guest_name', {duration: 0.5}); return false;}"} %>
> 
> <div id="guest_name" style="display:none;">
>   <h3>Name of guest?</h3>
>   <%= f.text_field :guest_name %>
> </div>
> 


Thanks Chris! I was able to get it working!

You're right about the Ajax not being needed, I'm just so used to 
thinking that anything that "pops up" is ajax, even though it doesn't 
need to be a server request. Sorry about that.

Two issues I'm having with this implementation though:

First, if I go to edit the form, I can see the '2' is selected but the 
guest_name field is hidden until I select a different number of tickets 
(I guess this activates/reloads the javascript). I even tried doing an 
if statement in the div: <div id="guest_name"<%= " style='hidden'" if 
[email protected] == '2' %>> which works (I can see this from the page 
source). However, the div is ALWAYS visible, until I select a different 
number of tickets and it acvtivates/reloads the javascript. Any ideas on 
how to get this to work?

Second, I ended up using a table structure for the form, wrapping the 
DIV around the <TR> doesn't work (the guest_name field is always 
visible). I'm guessing this is a table structure issue so I need to take 
a more in depth look.


Thanks again for the code Chris! It was extremely helpful.


-Tony
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
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