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

Example 7.4:
Returning Values


This Web page has just called a function which displays the Prompt box. The user types some text in and clicks on OK. The function 'returns' this text. Then the script writes the text into the Web document, below:


These are the scripts we used. First, in the HEAD: <SCRIPT LANGUAGE="JavaScript"> <!-- function function1() { var sTypedText sTypedText = prompt("Type some text, then click on OK.", "") return sTypedText } //--> </SCRIPT> Later in the Web page: <SCRIPT LANGUAGE="JavaScript"> <!-- var sText sText = function1() document.write("You just typed: <P><H3>" + sText + "</H3><P>") //--> </SCRIPT>
Previous Example-|-Next Example-|-Return to Chapter Listing