Generating new div when link is clicked

Hi everyone,

I'm new to rails, and I've got my application up and running. Now I'd
like to add a function that I haven't been able to find information
on.

Basically, I start with a form that asks the user to input the number
of widgets of some type they have.

For example (____ is a textfield):

_____ widgets of type ______.

Then I want to have a link below this that says "Add more widgets."
This would insert another line between the above and the "Add more
widgets" link. This would be able to be repeated as many times as the
user wants to enter widgets of many different types. Also, the new
lines should appear without refreshing the page.

Any help is appreciated. I hope this is the right forum. I figure
this will take some AJAX. I've done something similar before with
JavaScript, but it just hid/unhid a div.

Thanks,
Ryan

Hi
   You have to understand any ajax fashioned link One example

link_to_remote

http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M001645

   read it..Now also have a look at

insert_html

http://ap.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html#M000349

And check how page.insert_html works Examples avaible on the above link

Sijo

ryan8720 wrote:

Hi everyone,

I'm new to rails, and I've got my application up and running. Now I'd
like to add a function that I haven't been able to find information
on.

Basically, I start with a form that asks the user to input the number
of widgets of some type they have.

For example (____ is a textfield):

_____ widgets of type ______.

Then I want to have a link below this that says "Add more widgets."
This would insert another line between the above and the "Add more
widgets" link. This would be able to be repeated as many times as the
user wants to enter widgets of many different types. Also, the new
lines should appear without refreshing the page.

Any help is appreciated. I hope this is the right forum. I figure
this will take some AJAX. I've done something similar before with
JavaScript, but it just hid/unhid a div.

You don't need Ajax just to add more input fields: there's usually no
reason to make a server request for something so simple. It can be done
completely on the client side -- look at Element.clone() .

Thanks,
Ryan

Best,