Input Field Displaying Nan
Description Hi, I am using knock out. I have three checkboxes and an input field. When I click on checkbox, the value of the checkbox should appear on the input field. However, in
Solution 1:
Looking at the code, on this line,
total += parseInt(item);
the variable item is the value of your checkboxes.
<input data-bind="checked: selectedValues"type="checkbox" value="primaryClass">500</input>
<input data-bind="checked: selectedValues"type="checkbox" value="secondaryClass">200</input>
<input data-bind="checked: selectedValues"type="checkbox" value="otherClass">100</input>
meaning you are trying to parseInt("primaryClass")
... and so on.
Try changing the value of the checkbox to numbers.
Like here: http://jsfiddle.net/2L4W9/
Solution 2:
Check this out:
http://jsfiddle.net/Dtwigs/uFQdq/5/
Do your inputs like this to make them dynamic:
<label><inputdata-bind="checked: selectedValues, value: primaryClass"type="checkbox"></input><spandata-bind="text: primaryClass"></span></label>
Change your values to the values in text.
Post a Comment for "Input Field Displaying Nan"