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:
How do I get the value which is selected when the onchange event occurs
using RJS?
Thanks,
- Jens
View:
Code:
<%= javascript_include_tag :defaults %>
Test for Safari
%= form_tag :action => ‘do_something’, :id => @survey %>
<%= 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