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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:20:21+00:00 2026-05-23T23:20:21+00:00

Ok, I’ve got a unique one here and I’ve been searching all over the

  • 0

Ok, I’ve got a unique one here and I’ve been searching all over the googles and stackoverflow and found nothing that matches exactly what I need. Here’s what I’ve got.

I have three checkboxes in a form, these represent 3 different “events”. What I need is that if a person checks any ONE checkbox the total is $30. If they check any two of the boxes the total is $40 and if they check all 3 the total is $50. Since they may check any one, two, or all 3 boxes I can’t have the prices set statically in the value. I need something that say roughly “if 1 box selected, price is $30, if 2 boxes selected, price is $40, if 3 boxes selected, price is $50”.

I’m good with PHP and mySQL and I know I could accomplish this with PHP but I would have to submit the form first before the price would update, this is why I need javascript to update the pricing as the user checks/unchecks boxes. Thanks for all responses!

  • 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-23T23:20:22+00:00Added an answer on May 23, 2026 at 11:20 pm

    Here’s something that should get you started – this is all based on the assumption that there are only 3 checkboxes on your whole page and that you’re interested in all of them – you’ll want to make a method like this respond to your checkbox elements’ onclick events – I’ve found that to be more reliable than onchange.

            function updateTotal() {
                var checked = 0;
                var inputs = document.getElementsByTagName("INPUT");
                for (var i = 0; i < inputs.length; i++) {
                    if (/checkbox/i.test(inputs[i].type) && inputs[i].checked) {
                        checked++;
                    }
                }
    
                var priceInDollars = 0;
                switch (checked) {
                    case 1:
                        priceInDollars = 30;
                        break;
                    case 2:
                        priceInDollars = 40;
                        break;
                    case 3:
                        priceInDollars = 50;
                        break;
                }
    
                var priceElement = document.getElementById("the id of your element where you'll print the price");
                priceElement.innerText = "$".concat(priceInDollars.toString());
            }
    

    EDIT:

    I’m not a JQuery master yet – I like the JQuery answer for retrieving the count much better than mine – much cleaner…

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
i got an object with contents of html markup in it, for example: string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a JSP page retrieving data and when single or double quotes are
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,

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.