Section 5.7. 4. Write the callback function


5.7. 4. Write the callback function

Now that the Break Neck PHP script just returns a delivery estimate, we can write a new JavaScript function to display this to the customer. Let's figure out exactly what we need to do.

What we have: An HTML page with a main <div>, and a <form> within that <div> for taking orders.

Here's the main <div> for the page, with an id of "main-page".

The <form> has an id, "order-form", that we can use to look the <form> element up in the DOM.

What we want: An HTML page with a main <div>, and an order confirmation within that <div>.

This is the same <div> as in the original order form...

...but we've replaced the <form> with a text order confirmation.

What we need to do: Replace the <form> in the main <div> with the order confirmation.

  1. Get a reference to the <div> in the page, using its "id" attribute.

  2. Get a reference to the <form> in the page, using its "id" attribute.

  3. Create a new <p> element, and add a text confirmation of the order to the <p>.

  4. Replace the <form> element with the new <p> element (and its text node).

     form     div     p     Order confirmation     p Let's look at this step in a little more detail. 




Head Rush Ajax
Head Rush Ajax (Head First)
ISBN: 0596102259
EAN: 2147483647
Year: 2004
Pages: 241

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net