how to make this "if the checkbox is checked add total + 10000 if uncheck none"
because in this situation everytime i check or uncheck the checkbox it adds 10000

function AmmenitiesCALC(value){ 
newValue = parseInt(value); 
document.formcheck.Total.value = newValue;
document.formcheck.Total.value = Total; 

<th>AMMENITIES INCLUDED </th><td><input type="checkbox" name="Ammenities" value='10000' onClick="AmmenitiesCALC(this.value)"></td>
<td> </td>
<td> </td><th> Php 10,000 </th>
5 Years
Discussion Span
Last Post by DavidB

So, I am not clear on exactly what your issue is, but based on what I read from your post, i assume that you want to add 10,000 when the checkbox is checked, and subtract 10,000 when you uncheck it? correct?

Here is a modified demo with more than one option so you can see how it adds or subtracts as you check/uncheck.

I'm not an expert at JavaScript either so there may be other more efficient ways to handle this...

See --> jsFiddle Demo


<!DOCTYPE html>

  <td>Option 1</td>
  <td><input type="checkbox" name="option1" value='10000' onclick="myCalc(this)"></td>
  <td>Option 2</td>
  <td><input type="checkbox" name="option2" value='5000' onclick="myCalc(this)"></td>

<p>Total = <span id="Total"></span></p>

curVal = 0;
document.getElementById('Total').innerHTML = curVal;
function myCalc(e){
 newVal = parseInt(e.value);

 if (e.checked) {
  curVal = curVal + newVal;     
  document.getElementById('Total').innerHTML = curVal;
 } else {
  curVal = curVal - newVal;  
  document.getElementById('Total').innerHTML = curVal;

Edited by JorgeM


I do not see a conditional statement.
On line 4, I see Total+=newValue;, but it doesn't check first to see if checkbox checked. It adds 10000 to value regardless.

You should have code like the following:

if (checkbox checked){
else {
  do nothing;  // or whatever action should occur if checkbox unchecked
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.