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

  • SEARCH
  • Home
  • 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 4329284
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:48:12+00:00 2026-05-21T09:48:12+00:00

I need to calculate based on user input on the form below. While using

  • 0

I need to calculate based on user input on the form below. While using the jQuery Calculation Plug-in here: http://www.pengoworks.com/workshop/jquery/calculation/calculation.plugin.htm I was able to figure out how to do “How many sessions?” times “Number of Students” times “Cost Per Session” for the top two items. The one that is really stumping me is the bottom one where in addition to the user filling in number of sessions I need them to select the number of students from a select box as well. Any ideas?

<table>
<tr><th>How many sessions?</th><th>Number of Students</th><th>Type of tutoring</th><th>Cost Per Session</th><th>Total Cost</th></tr>
<tr><td><input type="text" name="qty_academic" size="3" /></td><td id="num_students">1 Student</td><td>Academic Tutoring</td><td id="price_item_1">$55.00</td><td id="total_item_1">$0.00</td></tr>
<tr><td><input type="text" name="qty_multi" size="3" /></td><td id="num_students">1 Student</td><td>ML Tutoring</td><td id="price_item_2">$60.00</td><td id="total_item_2">$0.00</td></tr>
<tr><td><input type="text" name="qty_group" size="3" /></td><td><select name="group_size" id="num_students">
    <option value=""></option>
    <option value="2">2 Students</option>
    <option value="3">3 Students</option>
    <option value="4">4 Students</option>
    </select></td><td>Group Tutoring</td><td id="price_item_3"></td><td id="total_item_3">$0.00</td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td><td colspan="2" align="right"><h3>Grand Total:</h3></td><td id="grandTotal"></td></tr>

The 2 student price would be $40 per student, 3 students = $35 per student, 4 students = $30 per student. Maybe I’m just not looking at this the right way but I can’t seem to wrap my head around it.

In addition to doing the calculations I also need to make at it a requirement of form submission that at least one session in one of those types be selected (as well as all the information fields I’m using on the rest of the form). Can someone point me to a good example of how to accomplish that? Thanks.


UPDATE #1:

Here’s what I have working so far: http://jsfiddle.net/jT9HE/2/

I just need to make it recalculate when the drop-down (select) box is changed.


UPDATE #2:

        $("select[name^=group_size]").bind("change", recalc);
        // run the calculation function now
        recalc();

This makes changes to the drop down box update the price. Now how can I determine the price based on what is selected in the drop down box?

  • 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-05-21T09:48:13+00:00Added an answer on May 21, 2026 at 9:48 am

    In my opinion this is a case where jQuery should complain. Anyway, actually a source of problems is the presence of multiple elements with the same value for the attribute id. This is a code excerpt showing the issue:

    <td id="num_students">1 Student</td>
    <td id="num_students">1 Student</td>
    
    <select name="group_size" id="num_students">
    

    When you do this,

    students: $("[id^=num_students]")
    

    the resulting element is not what you would like but the first TD.

    Hope this help for further investigation and code refactor.

    — UPDATE —

    I fixed your code, please take a look here on jsFiddle and see if it works for you. If not let me know.

    Basically I solved the issue of multiple id with the same value and added hidden fields in order to always have a number of students to multiply. Finally I attached an onchange event to the select box.

    There is also a bit of logic for dynamic calculation of prices for Group tutoring.

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

Sidebar

Related Questions

I need to calculate an end date based on todays date and a number
I need to calculate the time till Christmas in milliseconds. I'm using joda time
I have to calculate a total for each user based on individual actions --
i need an approach or an algorithm to pre-calculate an users interest based on
I'm using jQuery on this site, which has form inputs. I'd like one particular
I have a form that uses PHP to calculate a total based on the
I need to calculate distance from user location to specific location, when the app
*Note:Rephrasing my question based on user's comments. Need help on how to use .Net's
Is there a way to create a function as below? I need to calculate
I need to calculate the total of an invoice. This invoice is created with

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.