3.20. Test driveEven though there is plenty of work left to do, go ahead and take the coffee maker for a test drive. Be sure you've added the sendRequest(), getSize(), getBeverage(), and orderCoffee() functions to coffee.js, and then load coffee.html in your web browser. Enter in an order, and see what happens. Then, enter in another order... are both coffee makers being used? Jim's large mocha is brewing on the first coffee maker. Bob's order is brewing over on the seecond coffee maker.
I think it's confusing to have an order brewing, and have the details of that order still showing on the order form. Can't we clear the form when an order is placed? Let's clear the form when an order is placed Right now, your officemates enter their coffee order and click "Order Coffee". The coffee order is sent to a coffee maker, and brewing begins. But the order is still shown on the screen, and co-workers could be a little confused by that order still being on the screen. It would be a lot easier if once an order got sent to a coffee maker, the details were cleared from the form. You can clear a form using the reset() method. Let's add some JavaScript to orderCoffee(), in coffee.js, to clear the order form whenever an order is sent to a coffee maker: var status = getText(coffeemakerStatusDiv1); if (status == "Idle") { replaceText(coffeemakerStatusDiv1, "Brewing " + name + "'s " + size + " " + beverage); document.forms[0].reset(); There are two places in coffee. js where you send a request to a coffee maker. var url = "coffeemaker.php?name=" + escape(name) + "&size=" + escape(size) + "&beverage=" + escape(beverage) + "&coffeemaker=1"; sendRequest(url); } else { var coffeemakerStatusDiv2 = document.getElementById("coffeemaker2-status"); status = getText(coffeemakerStatusDiv2); if (status == "Idle") { replaceText(coffeemakerStatusDiv2, "Brewing " + name + "'s " + size + " " + beverage); In both places, get the first form on the web page, and call reset() on the form. document.forms[0].reset(); var url = "coffeemaker.php?name=" + escape(name) + "&size=" + escape(size) + "&beverage=" + escape(beverage) + "&coffeemaker=2"; Jim enters his coffee order just like before... ...and then clicks "Order Coffee"... ...which runs the orderCoffee() JavaScript function... Let's try these changes out. ...which sends the order to the first coffee maker, and then resets the form. Now, there's no confusion for the next person who wants to order a coffee.
|