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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:29:54+00:00 2026-06-16T07:29:54+00:00

I am trying to make small application which uses some html checkbox form objects.

  • 0

I am trying to make small application which uses some html checkbox form objects. Whenever any of those checkboxes are checked on or off, it runs a function which then changes the value of a variable unique to each checkbox. How would I go about making it so that using the arguments of the function – or some other means – I’m able to target the corresponding variable for whenever one of the checkboxes is clicked? Currently here’s what I’m attempting to accomplish.

HTML:

 <form action="" method="get" name="orderForm">
<input name="Test" type="checkbox" value="test" onchange="checkClick('1','5.00')" />Test 1<br />
<input name="Test" type="checkbox" value="test2" onchange="checkBoxClick('2','3.00')" />Test 2 <br />
<input name="Test" type="checkbox" value="test3" onchange="checkBoxClick('3','4.00')" />Test 3 <br />

And the Javascript:

//set global vars
var check1 = 0.00;
var check2 = 0.00;
var check3 = 0.00;

function checkClick(num,cost) {
    if (check+num == 0.00) {
        check+num = cost;
    }
    else {
        check+num = 0.00;
    }
    checkBoxClick();
}

function checkBoxClick() {
    document.getElementById("otherContainer").innerHTML = "<p>" + check1 + "<br />" + check2 + "<br />" + check3 + "<br />" + check4 + "</p>";
}

At the moment it’s just a crude test, but what I’m trying to do is make it so I only need one function that will handle each of the different checkboxes and their variables without having to make a different function for each one.

  • 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-16T07:29:56+00:00Added an answer on June 16, 2026 at 7:29 am

    I see what you’re trying to do. Make a variable check an array instead:

    var check = [ 0.00, 0.00, 0.00 ];
    

    Also, pass your parameters as numbers instead:

    checkClick(1, 5.00)
    

    But since arrays are 0-indexed, start with 0 instead of 1:

    checkClick(0, 5.00)
    

    And where ever you did check+num replace it with check[num].

    Here is the result:

    var check = [ 0.00, 0.00, 0.00 ];
    
    function checkClick(num, cost) {
        if (check[num] == 0.00) {
            check[num] = cost;
        } else {
            check[num] = 0.00;
        }
        checkBoxClick();
    }
    
    function checkBoxClick() {
        document.getElementById("otherContainer").innerHTML = "<p>" + check[1] + "<br />" + check[2] + "<br />" + check[3] + "<br />" + check[4] + "</p>";
    }
    

    BTW, you’re using check4 when you never made a check4 variable…

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

Sidebar

Related Questions

I'm trying to write a small wsgi application which will put some objects to
I am trying to make a small application which has the capability of showing
I am trying to make a small application for a project in which clients
I am trying to make a small application for my arm target. I have
I finished my small application and I am trying to make sure I have
I'm currently trying to make a small testing application for various programming tasks. It
I am trying to make an application which will notify current playing track's name
I'm trying to make a control for a silverlight application and I'm having some
I'm trying to make a small application that shows a notification for each 10
I am trying to make a small java application, and I need the corners

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.