Prev | Current Page 60 | Next

Larry Ullman

"Building a Web Site with Ajax: Visual QuickProject Guide"


4 Next, the function checks to
see if the browser supports the
document object model (DOM)
and, specifi cally, if the page has an
element with an id of results.
5 Finally, an onsubmit() event
is attached to the form (which has
an id value of emp_form). In other
words, when the form is submitted,
do the following??¦.
window.onload = init;
function init() {
var ajax = getXMLHttpRequestObject();
if (ajax) {
if (document.getElementById(???results??™)) {
document.getElementById(???emp_form??™).onsubmit =
function() {
Create a new JavaScript fi le that starts with the following code (see extra bits
on page 82):
adding records via Ajax 63
set up the Ajax
1 Tell the ajax object that you
want to use the POST method.
(See extra bits on page 82.)
2 Provide to the ajax object
the name of the page that
should be sent the request. This
is add_employee_xml.php, to
be written next.
3 When the ajax object??™s readyState value
changes, the handleResponse() function should be
called, passing that function this same object.
??¦
document.getElementById(???emp_form??™).onsubmit =
function() {
ajax.


Pages:
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72