286
Chapter 5
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 gure out exactly what we need to do.
4. Write the callback function
An HTML page with a main
<div>, and a <form> within
that <div> for taking orders.
What we have:
An HTML page with a
main <div>, and an order
conrmation within that <div>.
What we want:
Replace the <form> in the
main <div> with the order
conrmation.
What we
need to do:
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).
<div>
<div>
<form>
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.
This is the same <div> as in
the original order form...
...but we’ve replaced
the <form> with
a text order
conrmation.
form
div
p
Order conrmation
p
<p>
Send Order
HTML Form
PHP Script Callback
Let’s look at this step in a little more detail.
another break neck callback