Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7861227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:37:26+00:00 2026-06-02T22:37:26+00:00

i am using simple_nested_form and i hav this in my customer bill form <%=

  • 0

i am using simple_nested_form and i hav this in my customer bill form

<%= simple_nested_form_for @customer_bill do |f| %>
 <%= f.error_messages %>

 <%= f.label :employee_id %>
    <%= f.collection_select :employee_id, Employee.all,:id,:name, {:prompt => "Select Employee"}, :style => 'width:205px;' %><br />

            <%= f.label :date %>
            <%= f.datepicker :date, :dateFormat => 'dd MM, yy',  :showOn => "both", :buttonImage => "../assets/calendar.gif", :buttonImageOnly => true, :changeMonth => true, :changeYear => true, :placeholder => "Click on the Calender" %><br/>          

 <p><%= f.link_to_add "Add Product", :customer_bill_line_items %> </p>
  <p><%= f.submit %></p>
<% end %>

After i click the “add product” the following partial is been rendered

 <%= javascript_include_tag 'calculations' %>
     <hr/> 
    <%= f.hidden_field :user_id, :value => current_user.id %>
    <%= f.hidden_field :customer_bill_id %>

    <%= f.label :product_id %>
    <%= f.collection_select :product_id,Product.all,:id,:title, :prompt => "Select a Product", :style => 'width:150px;' %>&nbsp;&nbsp;&nbsp;<%= f.link_to_remove "Remove Product"%>
    <br/>

     <p class="fields">
<%= f.input :price, :class =>"price" %>
<br/>
<%= f.input :quantity, :class =>"qty" %><br/>

<%= f.input :amount, :class =>"amount"%><br/>
</p>

And i have this in my Calculations.js

jQuery(document).ready(function(){
jQuery(".price, .qty").keyup(function() {
        var p = jQuery(".price").val();
        var q = jQuery(".qty").val();
        jQuery(".amount").val(q * p);
    });
});

​

Now the Problem is First time wen i click “Add products” and i Enter ‘price’ and ‘quantity’ the amount is calculated inside the js file and is displayed in the ‘amount’ field and wen i click add product for second time, the calculations of the first is been rendered, it seems the js file is displaying the value calculated first time in every ‘amount’ field

What seems to be the problem? What can i do to make proper Calculations happen everytime i call the partial? need help urgently. Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:37:28+00:00Added an answer on June 2, 2026 at 10:37 pm

    Once your “add product” partial is rendered the second time, you have some elements on the page with duplicate id values (price, qty, amount). This is invalid HTML, and jQuery won’t be able to tell which ones you mean to bind keyup to.

    Try rewriting your partial and jQuery to avoid this problem. Either generate properly unique ids, or hook your keyup onto a different property (perhaps a class?). If you go for the latter route, you could also consider putting the jQuery into the page as a live call, rather than adding new keyup bindings for each new product.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have started using Simple-form and Bootstrap and I have tried to follow this
I have a nested form in a rails view that is called like this
I'm using ROXML to read and automatically build Ruby objects form properly formatted XML.
I have a nested form in a Rails 3.1 app, using Cocoon gem. In
I am using ryanb's simple_nested_form and i have the following Code <%= f.link_to_add Shipping
I am having trouble with my nested form. I am using Ryan Bates' code.
I am using Mongoid on Rails 3 and trying to build a nested form.
Greetings! This is my first question. I've searched all over the web as well
I'm using the CodeIgniter PHP framework. I have a simple form that has an
How can I find out which FORM an HTML element is contained within, using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.