I have a form with an input type text field, a select menu and a checkbox. Each form field stores a numerical value, depending on what the user enters, selects or checks.
Is it possible to use jQuery to add these three values and present the total in a fourth form field, in real time?
Here is my JSFiddle, which works if all of the fields are input type text, although I still can't get it to place the total value in the fourth form field:
jQuery
$('input').keyup(function(){ // run anytime the value changes
var firstValue = parseFloat($('#first').val()); // get value of field
var secondValue = parseFloat($('#second').val()); // convert it to a float
var thirdValue = parseFloat($('#third').val());
$('#added').html(firstValue + secondValue + thirdValue); // add them and output it
var firstValueComplex = parseFloat($('#firstComplex').val()); // get value of field
var secondValueComplex = parseFloat($('#secondComplex').val()); // convert it to a float
var thirdValueComplex = parseFloat($('#thirdComplex').val());
$('#addedComplex').html(firstValueComplex + secondValueComplex + thirdValueComplex); // add them and output it
});
HTML
<input id="second" value="0"></input><br />
<input id="third" value="0"></input><br />
<b>Total:<span id="added"></span></b><br />
<input id="firstComplex" value=""></input><br />
<select id="secondComplex">
<option value="0" selected>0</option>
<option value="15">15</option>
<option value="30">30</option>
</select><br>
<input type="checkbox" id="thirdComplex" value="16"> Add Value<br>
<b>Total:<span id="addedComplex"></span></b>
<input id="total" value="<span id=addedComplex></span>"></input>
http://jsfiddle.net/nathonjones/c3n5vc8f/3/
Hope you can help, thank you. NJ