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.
}
}
|