Im creating a form where i want the user to fill out an amount, and then show at the bottom of the form. Then if there is a checkbox checked it adds 21 to the value within the input field so far i have this, but its not quite working.
<label>Desired amount</label> <input name="tbDesiredAmount" type="number" id="tbDesiredAmount" min="50" />
<label>Include Apron?</label> <input id="cb_Apron" type="checkbox" name="cb_Apron" />
<p>Total: £<span id="total">0</span>.00</p>
$('#tbDesiredAmount').blur(function() {
var value = $('#tbDesiredAmount').val();
$("#total").empty().append(value);
});
$('#cb_Apron').blur(function() {
var value = $('#tbDesiredAmount').val();
var apron = 21;
var total = value + apron;
$("#total").empty().append(total);
});
So and example of what i want it to do.
- Type 70 into "desired amount", show 70 in #total when you focus off the input field.
- Check apron tickbox, adds 21 to the desired amount so displays 91 in #total
- if you uncheck the apron checkbox, it will remove 21 from the figure in #total
- if i change the desired amount, it will update the #total, this needs to work with the tickbox checked and the tickbox not checked.
Any help would be greatly appreciated as im rather stuck at the moment.
parseInt()
-var total = parseInt(value) + parseInt(apron);
– Krish R Apr 4 '14 at 11:14parseFloat()
. – Bharadwaj Apr 4 '14 at 11:17