15,877,966 members
See more:
How will I add the value of my checkbox to the value in my textbox? If the checkbox is checked, then it's value is added to the stotal, if not it will be ignored?

HTML
HTML
```<input type="text" id="sff" value="10.57"/>
<input type="text" id="osf" value="100.25"/>
<input type="checkbox" id="cb1" value="35.00"/>
<input type="text" id="total"/>```

JavaScript
```function subtotal(){
var a = \$("#sff").val();
var b = \$("#osf").val();

var stotal = parseFloat(a, 10)+ parseFloat(b, 10)+ parseFloat(cbtotal, 10);
\$('#total').val('\$' + stotal.toFixed(2));
}```
Posted

## Solution 1

Try this:
```<!DOCTYPE html>
<html>
<body>

<input type="text" id="sff" value="10.57" >
<input type="text" id="osf" value="100.25" >
<input type="checkbox" id="cb1" value="35.00">
<input type="text" id="total" >

<script>
\$('#cb1').click(function(){
var a = \$("#sff").val();
var b = \$("#osf").val();
var stotal = parseFloat(a)+ parseFloat(b);

if(\$(this).is(':checked')){
stotal = stotal + parseFloat(\$('#cb1').val());
}

\$('#total').val('\$' + stotal.toFixed(2));
})

</script>
</body>
</html>```

## Solution 2

JavaScript
```function subtotal() {
var a = \$("#sff").val();

var b = \$("#osf").val();
var c = 0;
if (\$('#cb1').is(":checked")) {
c = parseFloat(\$("#cb1").val(), 10);
}
var stotal = parseFloat(a, 10) + parseFloat(b, 10) + c ;

\$('#total').val('\$' + stotal.toFixed(2));
}
```

## Solution 4

C#
```//If the checkbox is checked, then it's value is added to the stotal, if not it will be blank.

function subtotal(){
var a = \$("#sff").val();
var b = \$("#osf").val();

var stotal = parseFloat(a, 10)+ parseFloat(b, 10);
\$('#total').val('\$' + stotal.toFixed(2));
}

\$('#cb1').change(function() {
\$('#total').val('');
if(\$(this).is(":checked")) {
subtotal();
}
});
});```