title: Change a variable in form based on selection within form
body: <p><strong>UPDATE 6/21/12</strong></p>
  
  <p>I have a form in rails that is working similar to an e-commerce checkout. </p>
  
  <p>The user selects a start hour, end hour, date, time and price preference(hourly, weekly, daily, etc.) in the form. The product already has a set price in the database that I'm converting to (hourly, weekly, daily, etc.) that I'd like to change based on the price preference and then get submitted with the rest of the form.</p>
  
  <p>I've been following Ryan's screencast on <a href="http://railscasts.com/episodes/88-dynamic-select-menus-revised?view=asciicast" rel="nofollow">dynamic select menus</a> but I'm wasn't sure how I'd fit his demo into my application since I don't want the user to select the price just the measure (daily/hourly/etc.) </p>
  
  <p>Gear has_many line_items
  line_items belongs to Gear and Carts</p>
  
  <p>Below is my code:</p>
  
  <p><strong>Gear Model (where I've created the price variables)</strong></p>
  
  <pre><code>class Gear &lt; ActiveRecord::Base
    attr_accessible :title, :size, :price, :sub_category_id, :user_id, :image, :image_a, :remote_image_url, :color, :year, :latefee, :cancellation, :minrental, :policy, :about, :address, :city, :state, :zip
    belongs_to :user
    belongs_to :sub_category
    has_one :category, :through =&gt; :sub_category
    has_many :comments, :dependent =&gt; :destroy 
    has_many :line_items
    has_many :calendars
    require 'carrierwave/orm/activerecord'
    mount_uploader :image, GearpicUploader
    mount_uploader :image_a, GearpicUploader
    before_destroy :ensure_not_referenced_by_any_line_item
  
    validates :title, presence: true
    validates :size,  presence: true
    validates :price, presence: true
    validates :sub_category_id, presence: true
    validates :user_id, presence: true
  
    def hourly_price
      price/24
    end
  
    def weekly_price
      price*7
    end
  
    def monthly_price
      weekly_price*4
    end
  end
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre><code>&lt;div class="gearside_date_top"&gt;
      &lt;%= form_for LineItem.new do |f| %&gt;
      &lt;p&gt;&lt;%= render :partial =&gt; "price" %&gt; / 
          &lt;%= f.select :day_or_hour, [['day', 1], ['hour', 2]], :id =&gt; 'day_or_hour' %&gt;
      &lt;/p&gt;
  &lt;/div&gt;      
  </code></pre>
  
  <p><strong>Partial Given to View</strong></p>
  
  <pre><code>&lt;em&gt;from&lt;/em&gt;
  &lt;span id="gear_daily" style="font-size: 190%; color: #94cbfc;"&gt;$&lt;%= @gear.price %&gt;&lt;/span&gt;
  &lt;span id="gear_hourly" style="font-size: 190%; color: #94cbfc; display:none;"&gt;$&lt;%= @gear.hourly_price %&gt;&lt;/span&gt;
  </code></pre>
  
  <p><strong>Javascript</strong></p>
  
  <pre><code>$('#day_or_hour').change(function() {
  
       var $index = $('#day_or_hour').index(this);
  
       if($('#day_or_hour').val() = '2') { 
       $('#gear_hourly').show(); 
       } 
       else {
       $('#gear_daily').show();//else it is shown
  
       }
  });
  </code></pre>
  
  <p>I can't seem to get it working.</p>