Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form action="" method="POST">
- <input type="text" name="text1" id="text1" class="sum" /><br />
- <input type="text" name="text2" id="text2" class="sum" /> <br />
- <input type="text" name="text3" id="text3" class="sum" /> <br />
- <input type="checkbox" id="chk1" value="4" class="sum" /><label for="chk1">4</label> <br />
- <input type="checkbox" id="chk2" value="10" class="sum" /><label for="chk2">10</label> <br />
- <select name="u1" class="chkOptions">
- <option value="0" selected="selected">нет</option>
- <option value="120">1 упаковка</option>
- <option value="240">2 упаковки</option>
- <option value="300">3 упаковки</option>
- </select>
- <input type="text" name="text" id="text">
- </form>
- <script>
- $(function() {
- var calc = function() {
- var sum = 0;
- fields.each(function() {
- var el = $(this),
- type = el.attr("type");
- if ((type == "text") || (type == "checkbox" && el.attr("checked"))) {
- sum += parseInt($(this).val(), 10) || 0;
- }
- $('#text').val(sum);
- });//end each
- },//end calc
- fields = $(".sum");
- fields.change(calc);
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement