Hello guys here the problem. I want to perform a different calculation based on the check box.
<div>
COD: <input type="checkbox" id="trigger" name="question" >
</div>
Here is the javascript for calculating the price of the item the problem is that i dont know how can i do the else if method
<script>
$("#price,#quant,#shipment").keyup(function () {
if(+myFunction3() =="" )
{
$('#demo').val(0);
}
else if($('#trigger')=="checked") //this is the problem
{
$('#demo').val($('#price').val() * $('#quant').val() ;
}
else
{
$('#demo').val($('#price').val() * $('#quant').val() + +myFunction3());
}
});
</script>
Advance thank you guys.
Once the checkbox is selected, we are calling prop() function as prop( "checked", true ) to check the checkbox and prop( "checked", false ) to uncheck the checkbox.
Checking if a checkbox is checked First, select the checkbox using a DOM method such as getElementById() or querySelector() . Then, access the checked property of the checkbox element. If its checked property is true , then the checkbox is checked; otherwise, it is not.
Using jQuery you could do:
else if($('#trigger:checked').length > 0)
or
else if($('#trigger').is(':checked'))
If you want to re-run your calculation when a user checks or un-checks the checkbox, you could run the same code you run on the keyup function on:
$('#trigger').change(function() {
...
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With