| Code | Interpretation of Code | |
|---|---|---|
| <HTML> <HEAD> <TITLE>CREDIT CARD INFORMATION FORM</TITLE> <HEAD> <SCRIPT LANGUAGE="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; } 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. */ var nr=0; nr1=document.form2.c_c_no.value; flg=0; str=""; spc="" arw=""; for (var i=0;i cmp="0123456789" tst=nr1.substring(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; } } </SCRIPT> </HEAD> <BODY TEXT="YELLOW" BGCOLOR="BLUE" LINK="#FFFFFF" VLINK="#551A8B" ALINK="#FF0000"> <CENTER><P><B><FONT SIZE=+3 >Credit Card information form </FONT></B></P>/CENTER;> <CREDIT CARD INFORMATION FORM> <FORM ACTION="http://ectweb2.cs.depaul.edu/my_name316/ asp_script.asp" METHOD=POST NAME="form2"> Credit Card Number<INPUT TYPE="TEXT" NAME = "c_c_no" SIZE=20 MAXLENGTH=20> <INPUT type="radio" name="c_c_type" value="visa" CHECKED>Visa < INPUT type="radio" name="c_c_type" value="mastercard">Mastercard < INPUT type="radio"name="c_c_type" value="discovercard">Discovercard <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> |
Function definition begin.
First object is document;display output
of form2. If credit card number or radio
typebuttom is empty then show alert message.
The element "c_c_no.value" is access from form
object. If the object is less than 5 numbers in
length then show alert. The "nrl"variable holds
the user input on the credit card value. Begin loop over each character in user's input; "nrl.length" is the length of input(crt card number); "i" is checking character by character. Begin block of code executed within loop Variable "cmp" holds characters allow to be input on the form. Function single out i-th character in user input.(i,i+1) returns a single character substring, and associate it with the "tst" variable. The condition uses two objects: cmp - list of allowed characters and tst - current character in the user input.The indexOf is the method applies to cmp object but it uses current character from the user input. If it cannot find a character in cmp object then it returns"-1" and the condition is true. The flg variable counts the number of unallowed characters. "++" sign increases the current value of the variable (in this case flg) by one. The "str" variable collects unallowed variables and display the unallowed string in the alert window prefixed by a space.The "+=" sign appends new value to current value of variable without destroying it. The "spc" variable collects unallowed characters. Arw displays the "^" sign for each unallowed character. Close the block of code that is executed if the condition is true. Otherwise append the "_" sign to arw variable. If the number of unallowed variables is not 0 then: This condition detects spaces among the unallowed characters appended to spc variable. Results: the "nrl" variable display user input. The "+" sign concatenates code, "\r" displays ENTER, the "arw" displays "^" and "_" signs to mark un/allowed characters. The "flg" holds number of unallowed characters in user input. The "str" displays all forbidden variables. End of function definition. End of code block. The form object name is form 2. Input window name is a radio buttom with credit card type. The OnClick event calls the multiple check function defined in the head. |