samedi 23 mai 2015

jQuery & JavaScript Excercise: Adding Values On Condition

How do you make it calculate using JavaScript/jQuery based on condition:

<!DOCTYPE html>
<html>
<body>

<form>
<fieldset>
<input type="checkbox" name="remark[]" value="Yes" class="answer">Yes
<input type="checkbox" name="remark[]" value="No" class="answer">No
<input type="checkbox" name="remark[]" class="answer">N/A
<input type="text" name="point1" class="score" value="3">
</fieldset>
<fieldset>
<input type="checkbox" name="remark[]" value="Yes" class="answer">Yes
<input type="checkbox" name="remark[]" value="No" class="answer">No
<input type="checkbox" name="remark[]" class="answer">N/A
<input type="text" name="point2" class="score" value="2">
</fieldset>
Total<input type="text" name="total" class="result">

</form>

</body>
</html>

  • on checkbox 'change' event.
  • if the checkbox is "Yes" or "N/A", the value of text boxes with default values next to it will be added and reflected in Total



Aucun commentaire:

Enregistrer un commentaire