Forum: Ruby on Rails Multiplicate values of 2 textfields in a multi model form

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.
M. S. (Guest)
on 2009-03-06 14:39
Hi all,

I tried to multiplicate two form fields in a tablerow just to inform the
user and without bothering the server. I'm sure this seems to be a
simple javascript problem, but all I got running was the following
example:

<tr class="<%= cycle('shade1', 'shade2') %> itemtablerow">
<% fields_for "offer[offer_item_attributes][]", itemtablerow do |f| %>
 <td><%= f.text_field        :pos_number,
:size => 2, :index => nil %></td>
 <td><%= f.collection_select :study_id, Study.find(:all), :id,
:index => nil %></td>
 <td><%= f.text_area        :description,
:index => nil %></td>
 <td><%= f.text_field        :amount,     :class => 'amount',    :size
=> 7, :index => nil %></td>
 <td><%= f.text_field        :price,         :class => 'price',
:size => 7, :index => nil %></td>
 <td><%= link_to_function 'product',
"alert(parseFloat($(this).up('.itemtablerow').down('.price').getValue())
                                                    *
parseFloat($(this).up('.itemtablerow').down('.amount').getValue()))"%>
 </td>
</tr>

How can I multiplicate the 'price' and the 'amount' fields and show the
product "onChange" in the tablerow?

Thanks in advance,
  Marco
This topic is locked and can not be replied to.