简体   繁体   中英

passing text_field values in ajx on rails

I'm using

<%= text_field 'person', 'one',:id => 'test', :onchange=>remote_function(:url=>{:action=>"update"}, :update=>"test") %>
<div id="test"></div>

Now I just want to send the value of text_field with :action ie :url=>{:action=>"update(value_of_text_field_entered"}

Don't want to use params[:person][:one].

Any suggestions?or how can I use <%= observe_field %> to send the value with action?

You can try this one also:
<%= text_field 'person', 'one' %>


### Paste following code in your javascript

$("#person_one").live("change", function(){
  $.ajax({
    complete:function(request){},
    data:'person_one='+ $(this).val(),
    dataType:'script',
    type:'get',
    url: '/update'route
  })
});

Use

<%= text_field 'person', 'one',:id => 'test' %>

<%= observe_field 'persone_one', 
     :url=>{:action=>"update"} ,
 :frequency => 0.25,
     :update=>'test',
     :with => 'person_one'
     %>

<div id="test"></div>

you get value of textfiled in params[:person_one]

也许您可以使用JavaScript代码“ this.value()”

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