views:

104

answers:

1

I am dynamically generating textboxes in ruby using <%0.upto(4) do |i| %>
<%= text_field_tag('relative_factor[]', @prefill_values[:relative_factor][i],:size => 6,:maxlength => 5) %> <%end%>

it generates following HTML markup

Another set of textboxes: <%0.upto(4) do |i| %>
<%= text_field_tag('rating_factor[]', @prefill_values[:relative_factor][i],:size => 6,:maxlength => 5) %> <%end%>

it generates following HTML markup

I have one more textbox:

.....

I want to update id="rating_factor_" textboxes as the value in either id="multiple" textbox changes or id="relative_factor_" textboxes changes.

E.g. id="multiple" textbox = 5

id="relative_factor_" value= 0.0 textbox = 1

id="relative_factor_" value= 1.0 textbox = 2

id="relative_factor_" value= 2.0 textbox = 3

id="relative_factor_" value= 3.0 textbox = 4

id="relative_factor_" value= 4.0 textbox = 5

I want to show (multiple multiple and relative_factor_ and show)

id="rating_factor_" value= 0.0 textbox = 5

id="rating_factor_" value= 1.0 textbox = 10

id="rating_factor_" value= 2.0 textbox = 15

id="rating_factor_" value= 3.0 textbox = 20

id="rating_factor_" value= 4.0 textbox = 25

Now if user changes,

id="relative_factor_" value= 1.0 textbox as 1.5

then

id="rating_factor_" value= 1.0 textbox should be updated as 7.5

To achieve above goal, I tried binding #relative_factor_ to keyup event but as id is same for all i.e.#relative_factor_, it returns value for first textbox i.e. id="relative_factor_" value= 0.0.

Please guide me to crack this problem.

Thanks in Advance.

+1  A: 

IDs are supposed to be unique! You can't have all your text fields sharing the relative_factor_ id.

You can do something like

<% 0.upto(4) do |i| %>
   <%= text_field_tag('relative_factor[][i]', @prefill_values[:relative_factor][i],
         :size => 6,:maxlength => 5) %>
<% end %>
j.