Retrieve a value from a form text field and set that value in another form text field using RJS?

Up vote 0 down vote favorite share g+ share fb share tw.

I am 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 The # '@variable' value should be accessible from the # 'element.

Replace_html' method stated below element Inspect end end How can I do that using the Prototype framework? Javascript ruby-on-rails ruby ajax ruby-on-rails-3 link|improve this question edited Jun 7 '11 at 18:03 asked Jun 7 '11 at 14:49user5020522,0111627 87% accept rate.

– user502052 Jun 7 '11 at 14:55 I wouldn't know, I stopped writting RJS a while ago. Not that I want to convince you, but what I usually do is respond the AJAX request not with Javascript but with JSON data (or HTML, if I just have to fill the view) and then JS code (already in the client) uses it. This ensures isolation between client and server code.

Sorry I cannot help you with your question. Anyway, why are you setting the observe there and not on page load? – tokland Jun 7 '11 at 15:02 @tokland asks: "Anyway, why are you setting the observe there and not on page load?

" My Answer: That code is stated in the view file. @tokland says: "Not that I want to convince you, but what I usually do is respond the AJAX request not with Javascript but with JSON data (or HTML, if I just have to fill the view) and then JS code (already in the client) uses it. " My Question: I understand a little bit... can you give me some more information (links, explanations, ...) on "isolation between client and server"?

– user502052 Jun 7 '11 at 17:58 ntecs.de/blog/articles/2006/12/18/… – tokland Jun 7 '11 at 20:15.

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()); }).

I don't use jQuery but Prototype... I updated the question. – user502052 Jun 7 '11 at 18:02.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions