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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:06:08+00:00 2026-05-20T08:06:08+00:00

I am wondering if it is possible to get two values from a checkbox

  • 0

I am wondering if it is possible to get two values from a checkbox in HTML form.

My code in HTML is something like this:

<input type="checkbox" name="order" value="20" > Sundae $20
<input type="checkbox" name="order" value="15" > Sandwich $10
<input type="checkbox" name="order" value="25" > Reg. Burger $30

The value set is the price of the orders. So that when I code it in Java servlet, I can total the amount ordered. (my code is something like this)

String [] price = request.getParameterValues("order");
int sumTotal = 0;
for (String sum : price){
    sumTotal=sumTotal+Integer.parseInt(sum);
}

out.println("<h1>Total Amount Purchased: $" + sumTotal  + "</h1>");

My problems are as follow:

I want to display the name of the order and the price before I total it but I can’t because I can only get the price value using this code:

String [] price = request.getParameterValues("order");`

How can I get the name of the item besides the price?
I want to call two values in my HTML like this:

<input type="checkbox" name="order" value="20" value="Sundae $20") Sundae $20 

so that in my Servlet the result would be like this:

 Ordered by Customer 1:
      Sundae $20
      Sandwich $10 
      Total: $30 <------//I could only do this

but I think it is not possible and I don’t know how to call it in java.

Also, how can I improve my code in getting the total amount?

  • 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-20T08:06:09+00:00Added an answer on May 20, 2026 at 8:06 am

    The “value” should be the name of the option:

    <input type="checkbox" name="order" value="sundae" > Sundae $20
    <input type="checkbox" name="order" value="sandwich" > Sandwich $10
    <input type="checkbox" name="order" value="burger" > Reg. Burger $30
    

    Now you know which items were selected (and not only their price).

    It breaks your code for computing the total price. However it was quite broken already. You must not rely on client-provided pride to decide of the total price on the server. The user can very easily send you a form reply with value of “1” and break everything.

    The server needs to know the price of each item and use it.

    String [] items = request.getParameterValues("order");
    int sumTotal = 0;
    for (String item : items) {
        sumTotal=sumTotal+prices.getPriceOf(item);
    }
    

    where

     prices.getPriceOf(item)
    

    provides the price of the ordered items (in fact the code should be more complicated than that: it should check if the item exist and so on).

    You might want to use a textbox instead of a checkbox in order to be able to order more than one item.

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

Sidebar

Related Questions

I was wondering if it is possible to do something like this: <uc1:TestControl ID=TestControl1
I'm wondering if this is possible. I have html like so: <p> <font face=Georgia>
I'm wondering if it's possible to get a handle on running instances of a
I was wondering if it's possible to run two projects at the same time
just wondering if it is possible to get the top 10 COUNT results and
I was wondering if it's possible to get to the name of the method
I was wondering is it possible to customize the tooltip that we get after
I am wondering if it is possible to get the real name of the
I'm wondering if it is possible to get the same grouping behavior of bar
I was wondering if it is possible to get the number of the line

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.