Section 3.18. Checking a coffee maker s status


3.18. Checking a coffee maker's status

Now that you can use the utility functions in text-utils.js, you can easily check the status of a coffee maker using the getText() function, like this:

 function orderCoffee() {     var name = document.getElementById("name").value;     var beverage = getBeverage();     var size = getSize();     var coffeemakerStatusDiv1 =     document.getElementById("coffeemaker1-status"); This gets the <div> that holds the status for the first coffee maker.     var status = getText(coffeemakerStatusDiv1);getText() will return the text in the coffeemaker1-status <div>.     if (status == "Idle") {     // Update the coffee maker's statusWe still need to figure out how to update the coffee maker's status, too.     var url = "coffeemaker.php?name=" + escape(name) +If the first coffee maker is idle, we want to send the coffee order to it, and let it brew the order.                             "&size=" + escape(size) +                             "&beverage=" + escape(beverage) +                             "&coffeemaker=1";         sendRequest(url);     } } 

 getText()getText() will return the text within a <div>, or any other element that you give it. text-utils.js has several JavaScript functions for working with the DOM. We'll cover the DOM in detail in Chapter 4. text-utils.jsAll the code in text-utils.js is in Appendix 2. You can check it out now, or wait until we've talked more about the DOM in Chapter 4. 




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