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;
Total+=newValue;
document.formcheck.Total.value = Total; 
} 

<tr>
<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>
</tr>

Recommended Answers

All 3 Replies

Javascript is not my strongest area but would it be better to do it this way?
http://jsfiddle.net/pixelsoul/Py5kb/

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>
<html>
<head>
 <title>Demo</title>
</head>
<body>

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

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

<script>
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;
 } 
}
</script>
</body>
</html>

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){
  Total+=newValue;
}
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, networking, learning, and sharing knowledge.