# Getting form field value within link\_to\_function

**URL:** <https://discuss.rubyonrails.org/t/getting-form-field-value-within-link-to-function/42517>\
**Category:** rubyonrails-talk\
**Created:** [May 14, 2009, 11:50am UTC](https://discuss.rubyonrails.org/t/getting-form-field-value-within-link-to-function/42517 "2009-05-14T11:50:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [May 14, 2009, 11:50am UTC](https://discuss.rubyonrails.org/t/getting-form-field-value-within-link-to-function/42517/1 "2009-05-14T11:50:13Z")

</div>

Hi all, I'm very new to this community, and I started practicing with Ruby on Rails just recently. I watched the 3 episodes , 72-73-74 for complex forms on railscasts , and I'm trying to deploy a "new" function for my form based on what I saw in the 3 episodes. So, I have a form for my master table, with 2 fields: one is named "from\_pl" and the other is named "to\_pl". What I'd like to achieve is the possibility of adding (to\_pl - from\_pl) children to the form with the click on a link. So my model is perfectly shaped, and the link Add child , in the vein of the referenced episode of railscasts is perfectly working, the code in the new.html.erb is \<%= link\_to\_function "Add Child" do |page| &nbsp;&nbsp;page.insert\_html :bottom, :percentages, :partial =\> 'percentage', :object =\> MatchPercentage.new end %\> I'd like to add more than 1 child , and I tried with a loop. So far, using &nbsp;&nbsp;\<%= link\_to\_function "Add Child" do |page| &nbsp;&nbsp;3.upto(6) do &nbsp;&nbsp;&nbsp;&nbsp;page.insert\_html :bottom, :percentages, :partial =\> 'percentage', :object =\> MatchPercentage.new &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;end %\> works fine. I'd like to substitute the 3 and the 6 with the values of the 2 fields in the form, which has not yet been submitted. I tried with a lot of different searches on the web, but didn't find anything suitable. Could you please enlighten me if there is a solution or not? Thanks a lot, Kind regards

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [May 14, 2009, 1:44pm UTC](https://discuss.rubyonrails.org/t/getting-form-field-value-within-link-to-function/42517/2 "2009-05-14T13:44:42Z")

</div>

OK guys, think I solved it by spending a little more time. Instead of using Ruby code for looping, I used js enflation with the page \<\< command. This is what did it for me: &nbsp;&nbsp;\<%= link\_to\_function "Add Child" do |page| &nbsp;&nbsp;&nbsp;&nbsp;page \<\< "for(i=$('from\_pl').value;i\<=$('to\_pl').value;i++) {" &nbsp;&nbsp;&nbsp;&nbsp;page.insert\_html :bottom, :percentages, :partial =\> 'percentage', :object =\> MatchPercentage.new &nbsp;&nbsp;&nbsp;&nbsp;page \<\< "}" &nbsp;&nbsp;end %\> Posting it as maybe someone else will need it. Cheers
