Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Learning  jQuery : Better Interaction Design and Web Development with Simple JavaScript Techniques
  • Table Of Contents Toc
  • Feedback & Rating feedback
Learning  jQuery : Better Interaction Design and Web Development with Simple JavaScript Techniques

Learning jQuery : Better Interaction Design and Web Development with Simple JavaScript Techniques

close
close
Learning  jQuery : Better Interaction Design and Web Development with Simple JavaScript Techniques

Learning jQuery : Better Interaction Design and Web Development with Simple JavaScript Techniques

Overview of this book

Table of Contents (18 chapters)
close
close
Learning jQuery
Credits
About the Authors
About the Reviewers
Preface

Numeric Calculations


Now we’ll move on to some manipulation of the actual numbers the user will enter in the shopping cart form. We have a Recalculate button on the form, which would cause the form to be submitted to the server, where new totals can be calculated and the form can be presented again to the user. This requires a round trip that is not necessary, though; all of this work can be done on the browser side using jQuery.

The simplest calculation on this form is for the cell in the Shipping row that displays the total quantity of items ordered. When the user modifies a quantity in one of the rows, we want to add up all of the entered values to produce a new total and display this total in the cell:

$('.quantity input').change(function() {
  var totalQuantity = 0;
  $('.quantity input').each(function() {
    var quantity = parseInt(this.value);
    totalQuantity += quantity;
  });
  $('.shipping .quantity').text(String(totalQuantity));
});

We have several choices for which event to watch...

Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Learning  jQuery : Better Interaction Design and Web Development with Simple JavaScript Techniques
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon