title: Why can't I add a value to a Rails hidden field using jQuery
body: <p>Thanks for your help with this one. The goal is to put some data from a selected option from a drop-down into a hidden field as the value. I've tested the basic idea outside of Rails with HTML (see a revised fiddle here: <a href="http://jsfiddle.net/e6zZB/1/" rel="nofollow">http://jsfiddle.net/e6zZB/1/</a>) and it works. It's only when I go to the Rails hidden field that the value doesn't seem to change. My way of testing is to select an option in the dropdown and then check the source to see if the value has been updated (not sure if that's a good way, though!) FYI, this is Rails 2 (it's an older project).</p>
  
  <p><strong>jQuery</strong></p>
  
  <pre><code>    $(document).ready(function(){
      $("#startdrop").change(function () {
            var startidval = this.options[this.selectedIndex];
            $("#start-masterlocation-id-field").val($(startidval).data("data-masterlocation-id"));
          });
      });
  </code></pre>
  
  <p><strong>Rails dropdown in view</strong></p>
  
  <pre><code>    &lt;select id="startdrop" name="startthere"&gt;
  &lt;% for location in @itinerary.locations %&gt;
  &lt;option data-masterlocation-name="&lt;%= location.masterlocation.name %&gt;" data-masterlocation-id="&lt;%= location.masterlocation.id %&gt;" value="&lt;%= location.masterlocation.street_address %&gt;, &lt;%= location.masterlocation.city %&gt;, &lt;%= location.masterlocation.state %&gt;, &lt;%= location.masterlocation.zip %&gt;"&gt;&lt;%= location.masterlocation.name %&gt;&lt;/option&gt;
  &lt;% end %&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p><strong>Rails hidden field in view</strong>  </p>
  
  <pre><code>    &lt;%= hidden_field :newsavedmap, :start_masterlocation_id, :id =&gt; "start-masterlocation-id-field" %&gt;
  </code></pre>
  
  <p><strong>Final Works</strong></p>
  
  <pre><code>    $("#startdrop").change(function () {
          var startidval = $(this).find('option:selected').attr('data-masterlocation-id');
          $("#start-masterlocation-id-field").val(startidval);
  });
  </code></pre>