JavaScript Tip of the Week for June 10, 1996: A Closer Look at Forms | Source Code | WebReference

JavaScript Tip of the Week for June 10, 1996: A Closer Look at Forms | Source Code

JavaScript Tip of the Weekfor June 10, 1996: Source Code: A Closer Look at Forms


Source code for the forms:
    <INPUT TYPE = "text" NAME = "user_name" VALUE = " type name here">
    <BR>    
    <INPUT TYPE = "radio" NAME = "Choice" VALUE = "1"
     onClick = "user_choice = 1">Apple<BR>
    <INPUT TYPE = "radio" NAME = "Choice" VALUE = "2"
     onClick = "user_choice = 2">Microsoft<BR>
    <INPUT TYPE = "radio" NAME = "Choice" VALUE = "3"
     onClick = "user_choice = 3">Netscape<BR>
    
    <INPUT TYPE = "button" NAME = "Okay_Then" VALUE = "Okay Then"
     onClick = "process(this.form)">



Source code for the form processing function, must come after the form code:
/* This code is Copyright (c) 1996 Nick Heinle and Athenia Associates, 
 * all rights reserved. In order to receive the right to license this 
 * code for use on your site the original code must be copied from the
 * Web site webreference.com/javascript/. License is granted to user to 
 * reuse this code on their own Web site if and only if this entire copyright
 * notice is included. Code written by Nick Heinle of webreference.com.
 */
function process()
    {
    if (user_choice == 0){
        alert("Fill out the form first!");
        }
    if (user_choice == 1){
        alert("Well " + document.test_form.user_name.value +
               ", you better hope Amelio turns Apple around.");
        }
    if (user_choice == 2){
        alert("Definitely a solid choice " + 
                document.test_form.user_name.value + ".");
        }
   if (user_choice == 3){
        alert("Stock goes up... Stock goes down... You\'re in for a rough ride "
                + document.test_form.user_name.value + " :-\)");
        }
    }