Book Image

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

Book Image

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

Overview of this book

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

Editing Shipping Information


The shopping cart page also has a form for shipping information. Actually, it isn’t a form at all when the page loads, and without JavaScript enabled, it remains a little box tucked away on the right side of the content area, containing a link to a page where the user can edit the shipping information:

But with JavaScript turned on, and with the power of jQuery at our disposal, we can turn this little link into a full-fledged form. We’ll do this by requesting the form from a PHP page. Typically the data populating the form would be stored in a database of some sort, but for the purpose of this demonstration, we’ll just keep some static data in a PHP array.

To retrieve the form and make it appear inside the Shipping to box, we use the $.get method inside the .click event handler:

$(document).ready(function() {
  $('#shipping-name').click(function() {
    $.get('shipping.php', function(data) {
      $('#shipping-name').remove();
      $(data).hide().appendTo('#shipping...