开发者

Binding KeyUp event to Input Field

I am dynamically generating textboxes in ruby using

6,:maxlength => 5) %>

it generates following HTML markup

Another set of textboxes:

6,:maxlength => 5) %>

it generates following HTML markup

I have one more textbox:

.....

I want to update id="rating_factor_" textboxes as the val开发者_运维知识库ue 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.


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 %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜