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>

Recommended Answers

All 3 Replies

Javascript is not my strongest area but would it be better to do it this way?

Even if not, you can see the "if ( this.checked === true )" in there which should help you.

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...


<!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;

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.