Lin_to_remote and update a text area

Hi,

I have a text area with id:"text_area" and in a link_to_remote tag I want to add content into the text area

I tried (Syntax was correct though not the exact one as below)

link_to_remote (update: "text_area",                url : { action => "update_text"},                position: bottom                )

The update_text action in the controller had

render :text => "This is new line"

THis does not work for text area, any help in the aspect would be good. If I have a div instead of text area it works but not for the text_area only.

Thanks, Sudhindra

You dont need an Ajax call for this. RJS is enough. in helper

  def add_text_link(name)     link_to_function name do |page|       page[:text_area] = "This is new line"     end   end

in view

<%= add_text_link "Insert text into text area using JS" %>

Ram wrote:

You dont need an Ajax call for this. RJS is enough. in helper

  def add_text_link(name)     link_to_function name do |page|       page[:text_area] = "This is new line"     end   end

in view

<%= add_text_link "Insert text into text area using JS" %>

On Mar 12, 7:18?pm, Sudhi Kulkarni <rails-mailing-l...@andreas-s.net>

Hi Ram,

Thanks for the help... this works but I have another question now what if I need to append into the text area instead of replacing the content?

Thanks, Sudhi

def add_text_link(name)   link_to_function name do |page|     page[:text_area] << "This is new line"   end end

page[:text_area].insert_html :bottom, "The new line"

This should work properly. The documentation for the methods available in RJS is located here, if you want to take a closer look: http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html

its inner HTML. So use <br/>

My suggestion was just a try.Just try everything you can think of with your code. its not going to affect anything else as far as i can see. It would help if you tell us more about what the error was.

Take a look at prototype.js api docs. Wouldnt take more than a couple of hours to go through the whole thing and it really helps. www.prototypejs.org/api

Also look out for RJS tutorials. Railscasts episodes 43-45 are good ones. www.railscasts.com/episodes/43

Here're a few RJS cheatsheets for quick reference http://thebitt.com/dropbox/rails/rjs_cheatsheet.pdf, http://slash7.com/assets/2006/10/8/RJS-Demistified_Amy-Hoy-slash7_1.pdf

Search the net thoroughly. More often than not, you can find a solution or the question has already been asked on some forum. And when you get errors that you cant resolve, post as much about them as you can so that others can help you.

$('text_area').value += ("\n Hello world" + name)

that should work or try..

$('text_area').value += ("\n Hello world" + "#{name} ")

But seriously.. keep trying different ways to get the result. you'll hit it just by brute force.