Retrieve a value from a form text field and set that value in another form text field using RJS
I 开发者_如何学Goam using Ruby on Rails 3 and I would like to retrieve a value from a form text field and set that value in another form text field using RJS as the following (or in a better way!):
update_page_tag do |page|
page.event.observe('text_field1_css_id', 'keyup') do |element|
element << ... # Get and set a '@variable' value using the value in the
# HTML textarea tag with id = 'text_field1_css_id'. The
# '@variable' value should be accessible from the
# 'element.replace_html' method stated below
element << ...
...
element.replace_html (:text_field2_css_id), @variable.inspect
end
end
How can I do that using the Prototype framework?
In prototype:
// /public/application.js
$('text_field_1_css_id').observe('keyup',function(event){
$('text_field2_css_id').setValue($F(event.element));
});
For others who might be interested, if you're using jquery, you can probably use:
// /public/application.js
$('#text_field_1_css_id').keyup(function(){
$('#text_field2_css_id').value($(this).value());
});
精彩评论