I am too new at javascript .. and have a problem with a simple coffee-script.
Script monitors 2 fields on a form and updates a third if the either of them changes. There "n" rows of the same type in the form. here is the code
line_pre = "#po_polines_attributes_"
watched = [ "_qty", "_unit_price"]
UpdateTotal = (ln) ->
jQuery ->
e1 = line_pre + ln + watched[0]·
e2 = line_pre + ln + watched[1]
new_total = $(e1).val()*$(e2).val()
res = line_pre + ln + "_total_price"
$(res).val(new_total)
#
for indx in [0, 1, 2]
do ->
for w_fld in watched
do ->
jQuery ->
$(line_pre + indx + w_fld).focusout ->
UpdateTotal(indx)
Code runs but only updates the last row of the data when qty or u_p are changed. I can't figure out why.
Also .. can anyone suggest how to find # of elements containing a string in jQuery/coffee $("input[name~='search_str']").length() doesn't work .. it appears that the returned element doesn't have "length/size" function.