Skip to Content
Head Rush Ajax
book

Head Rush Ajax

by Brett McLaughlin
March 2006
Beginner to intermediate
448 pages
13h 33m
English
O'Reilly Media, Inc.
Content preview from Head Rush Ajax
you’re on your way 4
111
ajax requests
With the address from the server, all that’s left is to update the web
form. Since the address is stored in a form eld, you can use the
DOM again, similar to how you got the value of the phone number
eld 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 */
document.getElementById(“address”).value =
customerAddress;
}
}
Since address is a form eld,
you can access the text in it
using the “value” property.
Here’s where
those id
attributes come
in handy again.
Q:
Why don’t we have to use that JavaScript utility file
from Chapter 1 to update the address field?
a: In Chapter 1, we were updating the text in a <span>
element. Since <span> isn’t an HTML element that you usually
type in, it doesn’t have a value property; the same is true for
most other HTML elements, like <p>, <em>, and <div>.
For form fields, though, you usually do need to enter a value.
To make that easier, you can just use the value property on a
form field element, and get and set its text value directly.
Q:
Couldn’t we just use a <div> for the customer’s
address? Why are we using a field, anyway?
a: Even though the Break Neck server looks up the
customer’s address, there are times when a customer might
want their pizza deliv ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

What Employees Want Most in Uncertain Times

What Employees Want Most in Uncertain Times

Kristine W. Powers, Jessica B.B. Diaz
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer
How to Become a Game-Changing Leader

How to Become a Game-Changing Leader

Douglas A. Ready, Alan Mulally

Publisher Resources

ISBN: 0596102259Errata PageSupplemental Content