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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:21:53+00:00 2026-06-14T18:21:53+00:00

I have this javascript code, that substracts from a total sum, a value when

  • 0

I have this javascript code, that substracts from a total sum, a value when a checkbox is checked. In my case for each checkbox checked it substracts 20.

<script language="JavaScript">
    function Calculate(){
    var tag = window.document.getElementsByClassName("hsnb"), total = <? echo $total; ?>;
    for (var i in tag){
        total -= tag[i].checked && !isNaN(Number(20)) ? Number(20) : 0;
    }
    var cucu = + total.toFixed(2);

    if(cucu < "20"){  
        alert("You dont have enough points!");
        for(i = 1; document.getElementById("bifa" + i) !== null; i++) {
            if (document.getElementById("bifa" + i).checked){

            } else {
                document.getElementById("bifa" + i).disabled = true;
            }
        }
    }

    window.document.getElementById("outputDiv").innerHTML = '<span style="font-size:20px;">You have: POINTS' + cucu + '</span>';
}​
</script>

I want to give each checkbox a certain value, let’s say:

<input type="checkbox" id="check" name="check" value="10">
<input type="checkbox" id="check" name="check" value="20">

And if i check the first checkbox it should substract 10 and if i check the second checkbox substract 20. You know what i mean, substract the value for each checkbox. Can you help me with this?

  • 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-14T18:21:55+00:00Added an answer on June 14, 2026 at 6:21 pm

    Hi you should try using jQuery, something like

    var sub = 0;
    jQuery("input[name=check]:checked").each(function(index, element){
        sub = sub + jQuery(element).val();
    });
    var total = yourNumber - sub;
    

    I’haven’t tested this snippet but it should work

    Hope it helps

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

Sidebar

Related Questions

I have this simple code that speaks for itself. <script language='javascript"> function check() {}
I have this code: <script id=toModify > Invalid javascript that will cause errors </script>
I have this javascript code <Script> function getGroupId(){ var group=document.getElementById(selectedOptions).value; var groupFirstLetter=group.substring(2); } </Script>
i Have this code that select all checkboxes: <html> <head> <script language=javascript> function checkAll(){
i have this jquery code: <script type='text/javascript'> $(window).load(function(){ $('input:checkbox').change(function(){ var tot=200; $('input:checkbox:checked').each(function(){ dat=$(this).val(); tot-=parseInt(dat);
I have this JavaScript code that creates a table, and puts in the rows
I have this javascript code below that uses jquery, it is suppoed to be
I have code that looks something like this in javascript: forloop { //async call,
I have this Javascript code I inherited from another developer. I am very new
I have this javascript code that creates a slider: http://jsfiddle.net/samccone/ZMkkd/ Now, i want to

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.