Forum: Ruby on Rails How to use input control in loop

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
nishi (Guest)
on 2009-05-19 10:07
(Received via mailing list)
Hi everyone,

i am using a <input type="text"> in a for loop. but not getting the
data as loop.
 also in controller how i will fatch the data of that loop.

Here is my code.

 <% for pros in @pros%>
                <tr>
                  <td><%=pros.name%></td>
                  <td>
                   <p> <a href="#" onclick="addpros
('txt_pros_total','txtpros<%=pros.id%>','txtT<%=pros.id%>'); return
false;"><img src="tuna.gif" alt="add" /></a></p>
                  </td>
                  <td>
                 <span id="txtpros<%=pros.id%>"  class="itemCount">0</
span>
                 <input type="hidden" name="txtT" id="txtT<%=pros.id
%>"  value="0"/>
                 <input type="hidden" name="txtpros" id="txtpros<
%=pros.id%>"  value=<%=pros.id%> ></input>
                  </td>
               </tr> <% end %>


Javascript:------

function addpros(theCount,txtpros,txtT)
  {
    if(parseFloat(document.getElementById(theCount).value) > 0){
    document.getElementById(theCount).value = parseFloat
(document.getElementById(theCount).value)-1;
    /*document.getElementById(txtpros).value = parseFloat
(document.getElementById(txtpros).value)+1;*/
    document.getElementById(theCount).innerHTML = parseFloat
(document.getElementById(theCount).innerHTML)+1;
    document.getElementById(txtpros).innerHTML  = parseFloat
(document.getElementById(txtpros).innerHTML )+1;
    document.getElementById(txtT).value  = parseFloat
(document.getElementById(txtpros).innerHTML );
}
  }

Here, im generating a table row by loop, which has to assign a value
in each row by the input control.

when i inspect the element its gives.
puts params.inspect

{"commit"=>"Finish", "captcha"=>"", "rating_overall"=>"",
"txtpros"=>"1", "txtT"=>"1",
"authenticity_token"=>"a5e1c967a1a70ddc4382dc6c0ff2342705e5e376",
"action"=>"add_review", "rating_terms"=>"", "controller"=>"managers",
"rating_performance"=>"", "comment"=>{"body"=>""}, "rating_Team"=>"",
"rating_strategy"=>""}
 here im getting single data.
but i need to get data from all rows.



could u plz help me as soon as possible.

Thanks,
Frederick C. (Guest)
on 2009-05-19 11:34
(Received via mailing list)
On May 19, 7:06 am, nishi <removed_email_address@domain.invalid> wrote:
> Hi everyone,
>
> i am using a <input type="text"> in a for loop. but not getting the
> data as loop.
>  also in controller how i will fatch the data of that loop.
>

long version: take a peak at
http://guides.rubyonrails.org/form_helpers.html
or http://www.spacevatican.org/2008/7/18/parametrised...

short version: Parameters need to be named appropriately (append [] to
the parameter name) for rails to handle them as arrays (rather than
ignoring duplicates)

Fred
This topic is locked and can not be replied to.