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 9024307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:58:28+00:00 2026-06-16T05:58:28+00:00

For different quantities, the unit price changes. I have a quantity dropdown box, a

  • 0

For different quantities, the unit price changes. I have a quantity dropdown box, a span for unit price, subtotal and total.

I want to make it so that when the dropdown box is changed, the unit price will updated, then subtotal will be updated, then the total price will be updated. So far I am using:

$('#quantity').change( function() {
    var pricetable = {
        "1": "368",
        "3": "338",
        "6": "298"
    }

    $('#unitprice').text(pricetable.$('#quantity').val());
    $('#subtotal').text($('#unitprice').val() * $('#quantity').val());
    subtotalsum();
});

I know that pricetable.$('#quantity').val() is wrong, but don’t know how to use $('#quantity').val() to lookup the JSON price table.

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-16T05:58:29+00:00Added an answer on June 16, 2026 at 5:58 am

    Like this:

    $('#unitprice').text(pricetable[$('#quantity').val()]);
    // Note the square brackets ---^--------------------^
    

    What you have there is a JavaScript object, not a JSON table. (JSON is a textual notation used for data exchange; this is source code. JSON is a subset of what you’re using there, which is JavaScript object initializer syntax.)

    In JavaScript, you can refer to a property on an object in one of two ways:

    1. Using dotted notation and a literal property name, e.g., obj.foo.

    2. Using bracketed notation and a string property name, e.g., obj["foo"]. (If you use something other than a string, it’s converted to a string before being used.)

    In the latter case, the string can be the result of any expression, it doesn’t have to be a literal.

    So in the line of code above, we get the current value of the quantity box, which will be a string like "1", "2", etc., and we use that to look up the relevant property in the pricetable object. Finally, we use that to set the text of the unitprice element.

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

Sidebar

Related Questions

Suppose I have quantities of fruits of different colors, e.g., 24 blue bananas, 12
We have 5,000 PDFs that should, in total, be no larger than 200gb. They
For different changes I made in my project, I need to restart Git repo
When different threads access a static method, are objects declared in that method local
How do you have different font sizes in a selects option in HTML4 <option
I'm writing a Boxee app that makes use of YouTube videos and I want
I thought I would try modeling some numerical integration on vector quantities of different
I have an array which contains error values as a function of two different
I have a project where I must make the following; You have a small
I'm developing a software that show's users spareparts searched with various different criteria. Spareparts

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.