CODE Explaination
<HTML> <HEAD> <TITLE>CREDIT CARD INFORMATION FORM </TITLE> <HEAD> <SCRIPT LANGUAGE="JavaScript"> This is the beginning of the HTML code.  It displays the Title in big bold print along the top and defines the script language as being JavaScript.
function multipleCheck() { formObj = document.form2; if (formObj.c_c_no.value == "") { alert("You have not filled in the name credit card number field."); formObj.c_c_no.focus(); return false; } else if (formObj.c_c_type.value == "") { alert("You have not selected the type of credit card."); formObj.c_c_type.focus(); return false; } The function multiple check assigns formObj to equal the document form2.  Then it checks IF the c_c_no (credit card number) is blank THEN alert (display a window) telling the user that they have not filled in the credit card number and return the focus (cursor) to the c_c_no text box.  ELSE IF the user typed in the credit card number but did not specify the type(c_c_type is blank), an alert window would tell the user that they didn't specify the type and the focus (cursor) would be returned to the type area.  The false value will be returned so that this form is not submitted until both these conditions are filled (c_c_no is filled AND type has been selected).
myformObj = document.form2.c_c_no.value; if (myformObj.length < 5) {alert("input is wrong"); formObj.c_c_no.focus(); return false;} /* ISN Toolbox Copyright 1996, Infohiway, Inc. */ The myformObj is a variable that is assigned the c_c_no value.  Then the IF statement checks the length of myformObj to be less than five.  If it is, THEN an alert 'input is wrong' is displayed and the focus (cursor) is returned to the c_c_no text box.   The value false is returned so that the form is not submitted unless the user fills the condition (length of c_c_no greather than five).
var nr=0; nr1=document.form2.c_c_no.value; flg=0; str=""; spc="" arw=""; Variables are being assigned.  nr is set to equal zero (0).  nr1 is equal to the document form2 c_c_no (credit card number) value.  flg is equal to zero (0).  str is set to blank.  spc is set to blank.  arw is set to be blank.
for (var i=0;i<nr1.length;i++) { cmp="0123456789" tst=nr1.substring(i,i+1) This is similar to a while loop -- this will continue to loop until it reaches the length of the c_c_no: FOR the variable i is set to zero (0); while i is less than the length of nr1 (c_c_no value) THEN i = i + 1. The cmp value (that was blank) is now set to equal the string "0123456789". tst is set to equal nr1 (c_c_no value) substring in the position i + (i+1).
if (cmp.indexOf(tst)<0) { flg++; str+=" "+tst; spc+=tst; arw+="^"; } else{arw+="_";} } if (flg!=0) { if (spc.indexOf(" ")>-1) { str+=" and a space"; } alert(nr1+"\r"+arw+"\rI'm sorry. This entry must be a number. I found " +flg+" unacceptable: "+str+"."); formObj.c_c_no.focus(); return false; } } The first line states if (cmp.indexOf(tst)<0). That means that IF cmp.indexOf (the string of 123456789) in the position of tst (i + (i + 1) is less than zero -- meaning that it has a value - - THEN flg is equal to flg + 1, str is concatinated with a space " " and then concatinated with tst. spc is concatinated with tst and arw is concatinated with the ^ symbol. ELSE the arw is concatinated with the _ symbol.
The if (flg!=0) checks if there any values outside the 0123456789 string. IF so, the spc indexOf checks if it's a space. IF it is a space then the str is concatinated with the " and a space" message to notify the user that they included a space within their c_c_no. ELSE if it's a different symbol, if will display a message that the entry must be a number and the flg (foreign value) is unacceptable. Then the focus (cursor) is returned to the c_c_no text box and the value false is set so that the form is not submitted until all conditions are tested and true.
</SCRIPT> </HEAD> </HEAD> <BODY> <CENTER><P><FONT SIZE=+3> Credit Card Information Form </FONT></P></CENTER> <FORM ACTION="http://ectweb2.cs.depaul.edu/my_name316/asp_script.asp" METHOD=POST NAME="form2"> The </SCRIPT> tells the browser where the script ends. The </HEAD> shows where the header ends. The <FORM> tag lists the beginning of a form where the action is to be posted to and asp. The name of the form is form2
<BR> Credit Card Number<INPUT TYPE="TEXT" NAME = "c_c_no" SIZE=20 MAXLENGTH=20> <BR> <INPUT type="radio" name="c_c_type" value="visa" CHECKED> Visa <br> <INPUT type="radio" name="c_c_type" value="mastercard"> Mastercard <br> <INPUT type="radio" name="c_c_type" value="discovercard"> Discovercard <br> <P><INPUT TYPE="SUBMIT" VALUE="Click here to submit the information" onClick="return multipleCheck()"></P> <P><INPUT TYPE="RESET" VALUE="Reset the screen"></P> <P></FORM></P> </BODY> </HTML> A Credit Card Number text is entered and then a text box (input type text) is placed next to it. This box has a maximum length of 20 characters.
Three radio buttons are created: Visa, Mastercard, Discovercard and values are assigned to each one so that the values can be identified.
A Submit button is created by entering Imput type=Submit. This will send the information in the form to the location specified in the Action within the Form tag.
A Reset button is created by entering Input type=reset. This will reset the screen (make the form blank again).
End of Form.
End of Body.
End of HTML.