Section 2.35. Finishing off the callback function


2.35. Finishing off the callback function

With the address from the server, all that's left is to update the web form. Since the address is stored in a form field, you can use the DOM again, similar to how you got the value of the phone number field in getCustomerInfo() way back on page 82.

 function updatePage()   {   if (request.readyState == 4) {     /* Get the response from the server */     var customerAddress = request.responseText;     /* Update the HTML web form */ Here's where those id attributes come in handy again.     document.getElementById("address").value = Since address is a form field, you can access the text in it using the "value" property.       customerAddress;You're using the DOM again... this time to set a value in the web form.Just set the field's value to the customer's address.   } } 




Head Rush Ajax
Head Rush Ajax (Head First)
ISBN: 0596102259
EAN: 2147483647
Year: 2004
Pages: 241

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net