• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Hour 14. Getting Data with Forms > Displaying Data from a Form

Displaying Data from a Form

As a simple example of using forms, Listing 14.1 shows a form with name, address, and phone number fields, as well as a JavaScript function that displays the data from the form in a pop-up window.

Listing 14.1 A Form That Displays Data in a Pop-Up Window

 1    <html>
 2    <head>
 3    <title>Form Example</title>
 4    <script LANGUAGE="JavaScript">
 5    function display() {
 6       DispWin = window.open('','NewWin',
          'toolbar=no,status=no,width=300,height=200')
 7       message = "<ul><li><b>NAME: </b>" + document.form1.yourname.value;
 8       message += "<li><b>ADDRESS: </b>" + document.form1.address.value;
 9       message += "<li><b>PHONE: </b>" + document.form1.phone.value + "</ul>";
10       DispWin.document.write(message);
11   }
12   </script>
13   </head>
14   <body>
15   <h1>Form Example</h1>
16   Enter the following information. When you press the Display button,
17   the data you entered will be displayed in a pop-up window.
18   <form name="form1">
19   <p><b>Name:</b> <input TYPE="TEXT" LENGTH="20" NAME="yourname">
20   </p>
21   <p><b>Address:</b> <input TYPE="TEXT" LENGTH="30" NAME="address">
22   </p>
23   <p><b>Phone: </b> <input TYPE="TEXT" LENGTH="15" NAME="phone">
24   </p>
25   <p><input TYPE="BUTTON" VALUE="Display" onClick="display();"></p>
26   </form>
27   </body>
28   </html>

					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint