<% form_for :customer, :url => {:action => :save_order} do |f| %>
<%= f.error_messages %>
<%= f.label :"Select Payment Method" %>
<%= f.select :payment_method, [['Cash','cash'],['Credit Card','credit card']] %>
<p>
<%= f.label :customer_first_name %><br />
<%= f.text_field :first_name %>
</p>
<p>
<%= f.label :customer_last_name %><br />
<%= f.text_field :last_name %>
</p>
<p>
<%= f.label :email_address %><br />
<%= f.text_field :email %>
</p>
<% if @customer.payment_method == "Credit Card" %>
<p>
<%= f.label :credit_card %><br />
<%= f.text_field :credit_card_number %>
</p>
<% else %>
<% end %>
<%= f.submit "Place Order"%>
Here’s my code. I just want the credit card number field to appear when the user selects credit card as their payment method. But when i select credit card in the drop down menu nothing happens. Thanks for your help!
Your
ifstatement will run server side, but you need client side logic to respond to the change in the drop-down list. You could show the credit card ‘p’ regardless, but hide it initially via CSS, then have some jQuery similar to this –