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
163
asynchronous applications
function getSize() {
var sizeGroup = document.forms[0].size;
for (i=0; i<sizeGroup.length; i++) {
if (sizeGroup[i].checked == true) {
return sizeGroup[i].value;
}
}
}
If we’ve found the option that is checked,
then return the value of that item.
orderCoffee() will call this function to
nd out what size coffee was ordered.
“document” is the entire web page,
and forms[0] is the rst form on
that page. Then, “size” is the name
of the <input> elements that let
users select their drink size.
Since there is more
than one element
named “size”, this
variable will be a
group of elements,
not just a single
<input> element.
This line loops through all the
elements in the “size” grouping...
...and this line checks to see if the
current element is checked (selected).
The returned value will be either “small”,
“medium”, or “large”, which is exactly what
the orderCoffee() function needs.
Getting the value of a radio group
The key to getting the size and beverage that Jim selected is
realizing that there are three different <input> elements, all
named “size” (and “beverage”). So you need to gure out which
of these three is currently selected:
It’s your turn to work with radio <input> elements.
First, open up coffee.js and add the orderCoffee(),
sendRequest(), and getSize() functions that we’ve
looked at over the last few pages.
Next, you need to writ ...
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