简体   繁体   中英

form not submitting selected value when updated via ajax (rails & jquery)

I have a form that has several drop downs, when one is chosen, it updates another. When I submit this form, the values of the drop downs that are updated via ajax dont get submitted. When I look at the form using firebug after its been updated, it looks good.

Here is my code

  var $j = jQuery.noConflict();

  $j(document).ready(
function(){
   $j('#source_credential_list').change(function(){
          var source_credential = $j("#source_credential").val();
         $j.post("/retrieved_data_records/keys_for_source_credential", {"source_credential":source_credential}, function(result) {
         });
         });
}

 <% form_tag  '/retrieved_data_records', :method => :get do %>

      <tr>
     <td>
        <b> Source Credentials</b>
        </td>
         <td>
               <span id="source_credential_list">
                  <%= render :partial => 'source_credential_list' %>
               </span>
         </td>
  </tr>
  <tr>
     <td>
        <b>Source Keys</b>
     </td>
    <td>
       <span id="source_key_list">
           <%= render :partial => 'source_key_list' %>
       </span>

     </td>
  </tr>
<div id="filtersButton"><td><%=submit_tag 'Filter'%></td></div>

The source_key_list partial:

 <%=select_tag :filter_source_key, options_from_collection_for_select(@all_source_keys, 'key_name', 'display_fancy_name', @selected_key.key_name)%>

Server side keys_for_source_credential returns:

 $j("#source_key_list").html("<%= escape_javascript(render(:partial => 'source_credential_key_list')) %>");

source_credential_key_list parital:

 <%=select_tag :filter_source_key, options_from_collection_for_select(@all_credential_keys.sort, 'key_name', 'display_fancy_name')%>

On my server the drop down value is not submitted. I guess I could manually post my drop down selection along with the form post, but it seems like it should be working...Im sure I am doing something dumb.

any ideas?

thanks Joel

原来我的问题是我有一个表格在表格之前开始,在表格之后结束,在表格内移动表格的开始和结束解决了我的问题。

我认为您不能使用val,而应使用文本

 $j("#source_credential").text();

I got same problem that form not submitting my selected value in select elecment.

I resolved by changing 'id' to 'name'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM