Guest
2006-Jun-06 11:26 UTC
[Rails] Getting value of form using Ajax (and problems with Safari)
I have got two forms, the first is a textarea plus a link that activates some javascript to change the form, the second activates some javascript on the onchange event which changes it into a textarea form. This works in Firefox, but not in Safari. Also, I need the value which is selected. I''ve found an example that gives the parameter to the javascript, like this: <input type="checkbox" name="name" onclick="new Ajax.Request(''<%= url_foraction => ''update_attribute'', :id => obj) %>'', {parameters:''name=''+this.name+''&value=''+this.checked})"/> How do I get the value which is selected when the onchange event occurs using RJS? Thanks, - Jens View: Code: <%= javascript_include_tag :defaults %> <h1>Test for Safari</h1> %= form_tag :action => ''do_something'', :id => @survey %> <div id="form1_1"> <%= q_item(1, 1)%> </div> <div id="form1_2"> <%= text_area("row1", "col2", { :cols => "20", :rows => "3" }) %> <div class="change"> <%= link_to_remote("change", :url => { :action => :change_back_div, :id => "form1_2" }, :id => "change") %> </div> </div> <%= submit_tag ''Send'' %> <%= end_form_tag %> helper: Code: module AdminHelper def q_item(row, col) return select("row"+row.to_s, "col"+col.to_s, %w{ Text Rating3 Rating4 ListItem GrantAccess}, {:include_blank => true}, { :onchange => remote_function( :url => { :action => :change_div, :id => "form"+row.to_s + "_" + col.to_s } ) } ) end def to_question_item_form id = params[:id] remote_function( :url => { :action => :change_div, :id => id } ) end admin_controller: Code: def change_div pos = args_id(params[:id]) html_options = { :class => "change" } render :update do |page| page[pos[:form]].replace( tag("div", "id" => pos[:form]) << text_area(pos[:row], pos[:col], {:cols => 20, :rows => 3}) << tag("div", "class" => "change") << link_to_function("change", remote_function( :url => { :action => :change_back_div, :id => pos[:form] }), html_options)) page.visual_effect :highlight, pos[:form], :duration => 2 end end def change_back_div pos = args_id(params[:id]) render :update do |page| page[pos[:form]].replace( tag("div", "id" => pos[:form]) << select(pos[:row], pos[:col], %w{ Text Rating3 Rating4 ListItem GrantAccess}, { :include_blank => true }, { :onchange => to_question_item_form } )) page.visual_effect :highlight , pos[:form], :duration => 2 end end -- Posted via http://www.ruby-forum.com/.
Jens Rasmussen
2006-Jun-06 11:30 UTC
[Rails] Re: Getting value of form using Ajax (and problems with Safa
Guest wrote:> I have got two forms, the first is a textarea plus a link that activates > some javascript to change the form, the second activates some javascript > on the onchange event which changes it into a textarea form. > This works in Firefox, but not in Safari. > > Also, I need the value which is selected. I''ve found an example that > gives the parameter to the javascript, like this:I posted this, just made an account :) - Jens -- Posted via http://www.ruby-forum.com/.