Jens Rasmussen
2006-Jun-06 08:39 UTC
[Rails] Get value from form using rjs, and problem with Safari
Hi,
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_for(:action =>
''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?
View:
<%= 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:
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:
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
Thanks,
Jens
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060606/e9fbbb83/attachment-0001.html
