Previous Example-|-Next Example-|-Return to Chapter Listing

Example 7.6:
Multiple Returns


This Web page calls a function which displays the Confirm box. The user clicks the OK or Cancel button. There are two different return statements depending on which button is clicked. The text returned is then displayed in the Web document, below:

These are the scripts we used. First, in the HEAD: <SCRIPT LANGUAGE="JavaScript"> <!-- function function1() { var bResultReturned bResultReturned = confirm("Click OK or cancel.") if (bResultReturned) { return "You pressed the OK button" } else { return "You pressed the Cancel button" } } //--> </SCRIPT> Later in the Web page: <SCRIPT LANGUAGE="JavaScript"> <!-- var sText sText = function1() document.write("<P><H3>" + sText + "</H3><P>") //--> </SCRIPT>
Previous Example-|-Next Example-|-Return to Chapter Listing