Binding KeyUp event to Input Field

Posted by user306686 on Stack Overflow See other posts from Stack Overflow or by user306686
Published on 2010-04-01T08:31:20Z Indexed on 2010/04/01 8:33 UTC
Read the original article Hit count: 238

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.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about jquery-ui