Skip to Main Content
Head Rush Ajax
book

Head Rush Ajax

by Brett McLaughlin
March 2006
Beginner to intermediate content levelBeginner to intermediate
448 pages
13h 33m
English
O'Reilly Media, Inc.
Content preview from Head Rush Ajax
ajax requests
function getCustomerInfo() {
var phone = document.getElementById(“phone”).value;
}
Connecting the DOM dots
Let’s use the DOM to get the customer’s phone number. Below, we’ve
connected the pieces of DOM code you saw on the last page, and added
them to the empty getCustomerInfo() function:
This just combines the pieces of JavaScript you saw
on the last page into a single line of code.
Let’s store the phone
number in a new variable.
<html>
<head>
<title>Break Neck Pizza Delivery</title>
<link rel=”stylesheet” type=”text/css” href=”breakneck.css” />
<script language=”javascript” type=”text/javascript”>
function getCustomerInfo() {
var phone = document.getElementById(“phone”).value;
}
</script>
</head>
<body>
<p><img src=”breakneck-logo.gif” alt=”Break Neck Pizza” /></p>
<form method=”POST” action=”placeOrder.php”>
<p>Enter your phone number:
<input type=”text” size=”14”
name=”phone” id=”phone” onChange=”getCustomerInfo()” />
</p>
<p>Your order will be delivered to:</p>
<p><textarea name=”address” rows=”4” cols=”50” id=”address”>
</textarea></p>
<p>Type your order in here:</p>
<p><textarea name=”order” rows=”6” cols=”50” id=”order”>
</textarea></p>
<p><input type=”submit” value=”Order Pizza” /></p>
</form>
</body>
</html>
The entire HTML page is
represented by the “document”
object in JavaScript.
getElementById(“phone”)
looks for an element with
an “id” attribute...
...with ...
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

Reinventing the Organization for GenAI and LLMs

Reinventing the Organization for GenAI and LLMs

Ethan Mollick
Head First Ajax

Head First Ajax

Rebecca M. Riordan

Publisher Resources

ISBN: 0596102259Errata PageSupplemental Content