Dynamic data assembling on internet client side5956709Abstract A new method is invented to assemble data into a data set, such as item list in an Internet shopping cart, on client side that is necessary for a transaction between two parties on the Internet server side and client side. The method is to arrange application logic and data access logic on both client side and server side according to execution efficiency to achieve optimal implementations of transactions. A web browser with a build-in engine that can execute client side application program, such as Netscape Navigator 3.0 or above, is needed to implement the method. Web pages used in the method are specifically designed in which client side application program written with script language, such as JavaScript, is embedded. Also a frame in a window, which is preferred, or a new window is created on client side as a data assembling monitor window. In addition, data needed for a transaction in web pages can be retrieved dynamically and individually and assembled with necessary user input in the monitor window by the client side application program actuated by users. In an assembling process, all or at least first two of following editing operations of adding, deleting, updating, entry check, calculation, and backup, are executed on client side until final submission, save, or print. An Internet Client Side Shopping Cart is used to illustrate how to implement this method by using HTML, JavaScript, and CGI. This method can also be used on a local area network and a metropolitan area network. Claims The invention claimed is: Description BACKGROUND OF THE INVENTION
__________________________________________________________________________
<HTML>
<HEAD>
<TITLE>GB Shopping Center</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<|-- start
//Put JavaScript client side application program here|||
// end-->
</SCRIPT>
</HEAD>
<FRAMESET COLS="20%,*">
<FRAME NAME="control" SRC="html/control.html" MARGINHEIGHT=2
MARGINWIDTH=1>
<FRAMESET ROWS="80%,*">
<FRAME NAME="display"SRC="html/whatsHot.html">
<FRAME NAME="cart" SRC="html/clearCart.html" onLoad="reload()"
onUnload="backup()">
</FRAMESET>
</FRAMESET>
</HTML>
__________________________________________________________________________
When this top file is loaded, the screen on client side is shown in FIG 1. JavaScript functions must be put between HTML tags "<SCRIPT LANGUAGE=`JavaScript`>" and "</SCRIPT>". The functions must also be between HTML comment tags "<|--"and "-->". The following functions introduced in this section are all put between these tags except noted otherwise. It should be noted that two handlers are assigned with the shopping cart frame, onLoad="reload()"16 onUnload="backup()"15 which are also shown in FIG. 7. It is found that when returning from visiting some other web sites by using Netscape Communicator 4.0, the characters in the shopping cart frame become unrecognizable characters. The two handlers here is to prevent that from happening by backing up and reloading the web page for the shopping cart frame. Also "reload" button on the Control Panel shown in FIG. 1 can be clicked to reload the backup copy of the web page for the shopping cart frame. On the Control Panel shown in FIG. 1, the control buttons is designed to control some major operations, such as fetching hot item list, search engine, and so on, to the Display Window, and deleting all items in the shopping cart by fetching a HTML file, named as "clearCart.htm", with header "Your Shopping Cart is Empty Now" and no other content. In the Display Window shown in FIG. 1, the item list or other HTML files can be displayed there. These files can be fetched from static HTML files on server side, and also from files produced on the fly by server side CGI programs which take data from item database or other files, or by client side application program. In the Display Window in FIG. 1, the item list is arranged in three columns. The first column is check boxes. If Internet shoppers want an item, by clicking in a box, the item named on the right of the clicked box will be added into the shopping cart at the bottom of the screen. The second column is items' names that also serve as links. By clicking on a link, a web page with pictures and/or introduction about the item can be fetched into the Display Window. The third column lists prices of items. By clicking on the link "Batman Soundtrack CD" in the Display Window of FIG. 1, a web page is fetched into the Display Window that can be used to show the picture and detailed introduction about this item as shown in FIG. 4. The following HTML code taken from "whatsHot.htm" file serves best to illustrate the item list design in the Display Window.
__________________________________________________________________________
<FORM NAME=formForDisplay>
<TABLE BORDER="0" CELLPADDING="5" CELLSPACING="5" WIDTH="462">
<TR>
<TD VALIGN=TOP WIDTH="6">
<P ALIGN="LEFT">
<|-In the "box" below, thc arguments in the function"top.pickup()" Are
(item ID, item name, unit price, order number of the link
". . ./html/item00.htm" in this homepage starting from zero)
->
<INPUT TYPE=CHECKBOX NAME=box onClock="top.pickupOneItem(`0001`,`Batman
Soundtrack
CD`,`$12.88`,0)"></A>
</TD>
<VALIGN=TOP WIDTH="280">
<A HREF=". . ./html/item00.html"TARGET="display"> Batman Soundtrack
CD</A>
</TD>
<TD VALIGN=TOP WIDTH="111">
<FONT SIZE="5" COLOR="#AF0000">$12.88</FONT>
</TD>
</TR>
//list all other items below.
</TABLE>
</FORM>
__________________________________________________________________________
The important information about the item is assigned as the arguments of the handler function "onClick=top.pickupOneItem(`0001`,`Batman Soundtrack CD`,`$12.88`0)"1. The four arguments of the handler function are item ID, item name, unit price, order number of the link "../html/item00.html" in all links of this homepage starting from zero. Upon an Internet shopper click on the check box, these four arguments will be passed to the handler function "pickupOneItem()"1 which is in the top file. Generally you can also assign these items' attributes with any object, or object's properties in a web page, as long as these object, or objects' properties are retrievable with client side application program. In FIG. 2 and FIG 3, two items have been selected and dropped into the shopping cart. The default quantity for items is one, but a shopper can change that at any time by focusing on the quantity cell and typing in a new number in the shopping cart. The shopper can also type in the tax rate if applicable into the tax rate cell. The total prices, subtotal, tax, and grand total are calculated automatically by client side application program. After finishing shopping, shoppers can put user ID and password in the shopping cart and submit the order by clicking on the button "Send This Order". If a shopper have not registered, by clicking on the "Registration" button on the Control Panel, a registration form will show up in the Display Window. After registration, the shopper can submit the order. In the Display Window of FIG. 4, for illustration purpose, a link "Put `Batman Soundtrack CD` into your cart|", a picture, and a radio button are designed into this web page which introduces "Batman Soundtrack CD". By clicking on any one of these three objects, the item will be dropped into the cart. The HTML statements for these three objects are
__________________________________________________________________________
<A HREF="javascript: top.pickupOneItem(`0001`,Batman Soundtrack
CD`,`$12.88`,4)">Put
"Batman Soundtrack CD" into your cart |<A>
By click on <BR>the picture below,<BR>add this CD<BR>into your cart
|<BR><A
HREF="javascript: top.pickupOneItem(`0001`,`Batman Soundtrack
CD`,`$12.88`,4)"><IMG
SRC=". . . /images/buttons/buyit.gif"><A>
<INPUT TYPE=RADIO NAME=radio onClick="top.pickupOneItem(`0001`,`Batman
Soundtrack CD`,`$12.88`,4)">
<A HREF=". . ./html/item00.html" TARGET="display">Batman Soundtrack
__________________________________________________________________________
CD<A>
Buttons can also be used for that purpose. In a real application, one of them is enough in an introduction file for one item. FIG. 5 shows a search engine displayed on the Display Window and created on the fly by clicking on the button "Search" on the Control Panel. This is an example that a web page is created on the fly by client side application program. The search engine can be used to search the store and display an item list in a same format as shown in the Display Window in FIG. 1. The button "What's Hot" and "Item Category" in the Control Panel are also designed for the same purpose to list items. FIG. 6 shows that a new window created on the fly by the client side application program is used as a client side shopping cart instead of using a flame as the shopping cart as shown in FIG. 1. The major difference between using a frame as a shopping cart and using a new window as a shopping cart is that reference from top file, Control Panel, and Display Window to the shopping cart and backwards is different. For example, referencing to an object in the frame shopping cart, named as "cart", from top file, "top.cart objectName" is used, but to an object in the window shopping cart named as "newWindow", "newWindow.objectName" is used. If referencing to a function in the top file from the frame shopping cart, "top.functionName" is used, but from the window shopping cart, "self.opener.functionName" is used. FIG. 7 and FIG. 8 illustrate, in logical flow, the functions performed by the client side application program in implementing the present invention and are hereinafter referred to in connection with the following description of exemplary operations of the Internet client side shopping cart In operation, the top file and the web pages associated with each flame of the window are downloaded by a user with a browser, such as Netscape Navigator 3.0, as shown in FIG. 1. The client side application program of JavaScript is compiled by the build-in JavaScript compiler of the browser. If a user clicks a check box in the Display Window in FIG. 1, function "top.pickupOneItem()" in top file is actuated by handler "onClick" 1. The function "top.pickupOneItem()" is listed below.
__________________________________________________________________________
//This function adds a new item into the cart. It also checks if the
newly added item
//is already in the cart. If so, it will focus on the quantity field of
that item in the cart.
//Then user can change the quantity there.
function pickupOneItem(itemID,itemName,unitePrice,linkOrderNum) {
//store item ID, itemName, unit price, and order number of the link
//in a array "numberName".
//Order number of links in a web page starting from zero. Of the four
parameters,
//the first is put into numberName›0!, second into numberName›1!, and so
on.
numberName=new Array()
numberName›0!=itemID
numberName›1!=itemName
numberName›2!=unitePrice
numberName›3!=linkOrderNum
if(top.cart.document.links.length =.ltoreq.0) {
//This is the first item which is put into shopping cart if true.
opSwitchBoard("firstItem", numberName)
else {
//there are some items already in the cart.
var numOfItemInCart=parseInt(top.cart.document.links.length)
var repeatItem=false
for (var i = 0; i < numOfItemInCart;i++) {
if (numberName›1! == top.cart.document.formForCart.elements›i*3!.name) {
//check if the newly added item is already in the shopping cart.
alert("This item is already in your cart| If you want more,
change the
Quantity, please|")
top.cart.document.formForCart.elements›i*3+1!.focus()
repeatItem=true
}
}
if(|repeatItem) {
//the newly added item is not in the shopping cart.
opSwitchBoard("addOneItem",numberName)
}
}
}
__________________________________________________________________________
In the shopping cart as shown in FIG. 2, each item name is also used as a link to a web page that introduce the item in details. This feature can be used to determine if there is any item in the shopping cart by the condition "top.cart.document.links.length=0". If it is true, there is no item in the shopping cart. Another way to do that is to put an empty form into file "clearCart.html" with the statement "<FORM NAME=formForCart></FORM>" in the body of the file. So the condition "top.cart.document.formForCart.elemetns.length=0", can also be used for the same purpose. In the condition expressions above, "cart" is the name of the shopping cart frame. For other terms, see JavaScript references. A determination is made at block 3 whether or not this is the first item selected. If it is the first item selected, a variable as a flag, named "mySwitch", is assigned a string "firstItem". If it is not, another determination is made at block 4 whether or not the selected item is already in the shopping cart. If it is, the cursor automatically focuses on the Quantity cell of the item in the shopping cart 5, users can make a decision to change quantity of the item or not. If no change is made, the program ends 2. If a change occurs, another function "top.totalPrice()" is actuated by an "onChange" handler 9. Now come back to block 4. If the item selected is not in the shopping cart, "mySwitch" is assigned a string "addOneItem". The flag string "firstItem" or "addOneItem" is then passed to the function "opSwitchBoard()" together with array "numberName" that contains information about the selected item, see above code of the function "top.pickupOneItem()". The function "opSwitchBoard()" is listed below.
______________________________________
function opSwitchBoard(mySwitch, numberName) {
if(mySwitch=="reload") {
writeToCart(cartBackup)
else {
var cart=writeToVarCart(mySwitch, numberName)
if(mySwitch|="backup")
writeToCart(cart)
}
if(mySwitch|="backup") {
calcSubtotal()
calcTax()
calcTotal()
mySwitch=null
}
}
______________________________________
The flow chart on FIG. 7 and FIG. 8 joins together at circle A 20. Two variables, "mySwitch" and "cartBackup", used in above code are global variables. The variable "cart" is a local variable. The variable "cart" is used to store the whole file of the web page for the shopping cart that is created by the client side application program on the fly. The global variable "cartBackup" is used to store the most recent copy of the content of the variable "cart". It is important to note that the whole file of the web page for the shopping cart is assembled into variable "cart" before writing or rewriting to the shopping cart frame. The function calls, "writeToCart(cardBackup)" 22 and "writeToCart(cart)" 40 in above code are used for implementing this final writing. The called function itself is shown as follows.
______________________________________
function writeToCart(cart){
top.cart.document.open()
top.cart.document.write(cart)
top.cart.document.close()
______________________________________
Block 21 is first determination block in the function "opSwitchBoard(mySwitch, numberName)" above. If it is false, the program begin to write the file of the web page for the shopping cart into variable "cart". Function "writeToVarCart(mySwitch, numberName)" below is called first.
__________________________________________________________________________
//this function write a web page for the cart, but put the content of the
page into a variable "cart" first.
function writeToVarCart(mySwitch, numberName) {
var cart=writeCartHeader()
if(mySwitch|="firstItem") {
cart+=keepOldItemsInCart()
if(mySwitch=="firstItem" .vertline..vertline. mySwitch=="addOneItem") {
cart+= putNewItemIntoCart(numberName)
}
cart+= writeSubtotal()
cart+= writeTax()
cart+= writeTotal()
cart+= writeCartFooter()
cartBackup=cart //backup the content of the web page for the cart.
return cart
}
__________________________________________________________________________
First the header is written 24. The following code is to do the job.
__________________________________________________________________________
//Function that write a head, a title, a form title, etc. of a web page
on the fly. The web page is used as
//a client side shopping cart and displayed in the shopping cart frame
when completed.
function writeCartHeader() {
var cart ="<HTML><HEAD><TITLE>
cart +="Your Shopping Cart</TITLE></HEAD>"
cart +="<BODY>"
cart +="<center><h2><hold>Your Shopping Cart<h2></bold><(center>"
cart +="<P><FORM NAME=`formForCart` ACTION=`http://URL of CGI program
which receives the
submitted form` METHOD=`POST` TARGET=`display`>"
cart +="<TABLE BORDER=0 WIDTH=`100%`>"
cart +="<TR>"
cart +="<VALIGN=TOP WIDTH=`100%`>"
cart +="<TH ALIGN=LEFT>Description</TH>"
cart +="<TH ALIGN=RIGHT>Unit Price</TH>"
cart +="<TH ALIGN=RIGHT>Quantity</TH>"
cart +="<TH ALIGN=RIGHT>Total Price</TH>"
cart +="</TR>"
cart += writeHrOrBlankLine("HR")
return cart
__________________________________________________________________________
Note that the form in the shopping cart is named as "formForCart". The "ACTION" of the form refers to a CGI program that will retrieve the data in the form of the shopping cart, and write the data to the file or database on the server side. The four column titles are Description (item's name), Unit Price, Quantity, Total Price. See FIG. 2 for details. The function call "writeHrOrBlankLine("HR")" in above code write a horizontal rule if "HR" is passed to the called function. If no argument is passed, a blank line is written into the shopping cart At block 28, the flag "mySwitch" is checked against "firstItem". If "mySwitch" equals "firstItem", then at block 31 the condition is also true. The first item is dropped into the shopping cart 30. The following function "putNewItemIntoCart(numberName)" is to do the job.
__________________________________________________________________________
function putNewItemIntoCart(numberName){
//In the cart, first column is item name with a link to homepage that
introduce the item.
var cart ="<TR><TD><A HREF="+top.display.document.links›parseInt(numberNam
e›3!)!+"
TARGET=`display`>"
cart +=numberName›1!+"</A>"+"</TD>"
//The second column is unit price. Its type is text of form with
NAME=item name and
/VALUE=unite price
cart +="TD ALIGN=RIGHT><INPUT TYPE=TEXT NAME=.backslash.`"+numberName›1!
cart +=".backslash.`VALUE=.backslash.`"+numberName›2!+ ".backslash.`
SIZE=6 onFocus=top.cartWarning(this)>"+">/TD>"
//The third column is the quantity. Its type is text of form with
NAME=item ID and
//VALUE=quantity.CGI program on server side should retrieve this pair of
data to form the order
cart +="<TD ALIGN=RIGHT><INPUT TYPE=text NAME=.backslash.`"+numberName›0!
cart+=".backslash.`VALUE=`1` onChange=`top.totalPrice(this,
this.form)`SIZE=3></TD>"
//The forth column is total price. Its type is text of form with
NAME=`totalPrice` and
//VALUE=total price
cart +="<TD ALIGN=RIGHT><INPUT TYPE=TEXT NAME=totalPrice
VALUE=.backslash.`"+
numberName›2!+".backslash.`SIZE=10 onFocus=top.cartWarning(this)></TD>"
cart +="</TR>"
return cart
}
__________________________________________________________________________
In the above code, "top.display.document.links›ParseInt(numberName›3!)!" is used to retrieve the link object in the Display Window which holds a URL for a web page that introduces the item in details. Also note that how the item ID, item name, and unit price are assigned as objects' names and values that are retrievable individually by the client side application program later if needed. After put the first item into the variable "cart" 30, the programs continue to write subtotal 32, tax 34, total 35, and footer 37 into the variable "cart". Then a copy of the variable "cart" is stored into the global variable "cartBackup" 38. Because it is the first item, the logic flow of the program goes from block 41 to block 40, and finally the shopping cart frame is written with a web page for the first item. The default quantity of the item is one. Shoppers can change the quantity at any time in the shopping cart, and the total price will be recalculated. The new values in the text cells of the shopping cart can be written by the client side application program without causing the whole file of the web page for the shopping cart to be rewritten. This is a relative new feature of Netscape Navigator 3.0 and above. Functions such as "calcTotalPrice()" 12, "calcSubtotal()" 43, "calcTax()" 42, and "calcTotal()" 39 in top file all take the advantage of this feature, and make the update operations easier. On the other hand, if an item is added or deleted from the shopping cart' the whole file of the web page for the shopping cart has to be rewritten if Netscape Navigator 3.0 or Communicator 4.0 is used. Function calcSubtotal() is listed below.
__________________________________________________________________________
//subtotal=sum of all totalPrice
function calcSubtotal() {
var numOfItemInCart=parseInt(top.cart.document.links.length)
var subtotal=0
var value=""
for (var i = 0; i < numOfItemInCart; i++){
//calculate the sum of the totalPrice
value=top.cart.document.formForCart.elements›i*3+2!.value//total price
for each item
value= deleteString(value,"$")
//delete "$" from money value
value= parseFloat(value)
//change to float number
subtotal+=value //sum up total price
subtotal=formatNum(subtotal,2)
//keep only two digit after thc decimal point
top.cart.document.formForCart.elements›numOfItemInCart*3!.value
="$"+subtotal //write back to the
shopping cart frame
calcTax()
calcTotal()
}
__________________________________________________________________________
In this function, there are a few utility functions to implement number and string manipulations. In JavaScript reference books, one can get information on how to write them. If a new item is added into the cart, the whole HTML file for the cart has to be rewritten. First the data of the items already in the cart has to be retrieved into variable "cart", and then the data of the newly added item. Then put the old items into the cart (write the part of web page for the shopping cart on the old items), and then add the new item. The following function is to retrieve data on the old items already in the shopping cart, and then put into the variable "cart" again before adding the new item.
__________________________________________________________________________
//This function put the data of the items already in the shopping cart at
the top of the cart
//when new item is added.
function keepOldItemsInCart() {
var numOfItemInCart=parseInt(top.cart.document.links.length)
var cart=""
for (var j = 0; j<numOfItemInCart; j++) {
if(top.cart.document.formForCart.elements›j*3+1!.value |="0") {
//put the old items into the cart if quantity |=0
cart +="<TR><TD><A HREF=.backslash.`"+top.cart.document.links›j!
cart +=".backslash.`TARGET=display>"
cart +=top.cart.document.formForCart.elements›j*3!.name+"+"</TD>"
cart +="<TH ALIGN=RIGHT><INPUT TYPE=TEXT NAME=.backslash.`"+ top.cart.docu
ment.
formForCart.elements.differential.j*3!.name
cart +=".backslash.`VALUE=.backslash.`"top.cart.document.formForCart.eleme
nts›j*3.!.value
cart +=".backslash.` SIZE=6 onFocus=top.cartWarning(this)>" +"</TD>"M
cart +="TD ALIGN=RIGHT><INPUT type=text name=.backslash.`"+ top.cart.docum
ent.
formForCart.elements›j*3+1!.name
cart +=".backslash.` VALUE=.backslash.`"+top.cart.document.formForCart.ele
ments›j*3+1!.value +".backslash.`size=3
onChange=`top.totalPrice(this, this.form)`></TD>"
cart +="<TD ALIGN=RIGHT><INPUT TYPE=TEXT NAME=totalPrice"
cart +="VALUE=.backslash.`"+top.cart.document.formForCart.elements›j*3+2!.
value+".backslash.` SIZE=10"
cart +="onFocus=top.cartWarning(this)></TD>"
cart +="/TR>"
}
return cart
}
__________________________________________________________________________
In this function, how many items in the cart are first detected by the JavaScript statement "var numOfItemInCart =parselnt(top.cart.document.links.length)". This number is used in block 29 to control the loop. Because of each link in the cart corresponding one item, the number of links is equal to the number of the items in the cart. Another reason to put the links in the cart is that shoppers can check the item information at any time by fetching the linked web page into the Display Window without any browsing, see FIG. 4. Also note how links, item IDs, item names, unite prices, and quantities are retrieved individually and put on the top the shopping cart before adding a new item. Before putting each old item into the cart, the Quantity of the item is checked against zero 25. If shoppers put the quantity of an item in the cart to zero, total price for that item is recalculated automatically 9, 12. When the total price of the item is zero, the function will not put it into the cart again. So that the item is automatically deleted 14, 19. This function is triggered whenever shoppers put the quantity of an item to zero by the event handler "onChange=""top.totalPrice" 9. Another important point is that Netscape Navigator treats check box, text cell, text area, buttons in a form as elements but links. So for item j in the cart item list, element›j.sup.* 3! refers to unite price cell of item j, elements›j.sup.* 3+1! refers to quantity cell of item j, and elements›j.sup.* 3+2! refers to total price cell of item j, see FIG. 2. Another feature is that elements and links are counted staring from 0. This is typical C and C++ program languages' feature. When the use try to change the values in the unite price cell, total price cell, subtotal cell, tax cell, and total cell by clicking on the cell, the following function first changes the cell in the shopping cart to blur, and then gives an alert to users that "You can't change this cell by yourself |". In this way, all of this kind of trying will be screened out.
__________________________________________________________________________
//Screen out all illegal effects to changes unit price, total price, and
so on.
function cartWarning(thisPoint) {
var length=top.cart.document.formForCart.elements.length
for(var i = 0; i <length; i++) {
if(thisPoint.name==top.cart.document.formForCart.elements›i!.name) {
//check which cell the user is clicking on, and make it unaccessible
top.cart.document.formForCart.elements›i!.blur()
}
alert("You can't change this field by yourself|")
}
__________________________________________________________________________
For the quantity cell, only positive integer is allowed. For the tax rate cell, only positive number is allowed. For the user ID and password cells, only number and alphabetic characters are allowed. If an illegal character is entered, an alert will be shown up on screen to remind users to change to the legal character sets. If users change the Quantity of an item in the shopping cart 9, total price will be recalculated 12. If the total price is not equal to zero 14, subtotal, tax, grand total will be automatically updated 13, 12, 10. Then the program ends 8. Also every time when a new item is added, an item is deleted from the shopping cart, or the web page for the shopping cart is reloaded, subtotal, tax, grand total will be automatically updated 42, 39, 36. In this shopping cart design, the data assembling monitor window using a frame as a shopping cart is set by the top file directly with HTML frame tags. Also the HTML file assigned to a frame by the top file can set subframes. If a new window is to be used as a data assembling monitor window, the window can be set by the top file indirectly with the embedded client side application program. When the data set in the shopping cart is ready to be submitted, CGI programs on the server side can do rest of the job for the transaction. After receiving the submitted data set, CGI program can make some necessary checks. If every thing seems to be right, the data set can then be saved in a file or a data base. Because CGI program design is already in the conventional category of the art for programmers, no further description is made here. The client side application program in this shopping cart application is written with JavaScript. Other languages, such as JScript, VBScript, combination of JavaScript and Java through LiveConnection, etc., and their future versions, can also used to program the client side application programs. Even some new computer languages may be created to do the job in future. As shown by the Internet client side shopping cart design in this description, programmers have the enormous flexibility to design various Internet client side application programs just as they do in the Internet server side. With well-designed web pages and CGI programs on the Internet server side, plus well-designed Internet client side application programs, the Internet will be a more interesting place for people to visit. Some functions that are not cited in above description are listed below. All these functions cab be embedded in the top file in any order. Some or all of these functions can also be embedded in other file or files, but reference must be changed accordingly. There are a few utility functions not listed in this description that implement number and string manipulations. In JavaScript reference books, normally skilled programmers familiar with JavaScript can get information on how to write them and easily write them by themselves.
__________________________________________________________________________
// function to check if the input is a valid number
function isValidNumber(inputStr) {
if (isEmpty(inputStr)) {
alert("Please enter a number into the field |")
return false
else {
if (|isNumber(inputStr)) {
alert("Please make sure entry is a number|")
return false
}
}
return true
}
// function to check if the input is a valid positive number
function isValidPosNumber(inputStr) {
if (isEmpty(inputStr)) {
alert("Please enter a positive number into the field |")
return false
}
else {
if (|isPosNumber(inputStr)) {
alert("Please make sure entries is a positive number|")
return false
}
}
return true
}
// function to check if the input is a valid positive integer
function isValidPosInteger(inputStr) {
if (isEmpty(inputStr)) {
alert("Please enter a positive integer into the field |")
return false
}
else {
if(|isPosInteger(inputStr)) {
alert("Please make sure entries is a positive integer|")
return false
}
}
return true
}
function isValidAlpha(inputStr) {
if (isEmpty(inputStr)) {
alert("Please enter letters.")
return false
}
else {
if (|isAlpha(inputStr)) {
alert("Please make sure entries are letters only.")
return false
}
}
return true
}
function isValidAlphaNum(inputStr) {
if (isEmpty(inputStr)) {
alert("Please enter letters or number or their combination.")
return false
}
else {
if (|isAlphaNum(inputStr)) {
alert("Please make sure entries are letters or number or their
combination.")
return false
}
}
return true
}
//Checking user's ID and password
function isValidIDPasswd( ) {
var length=top.cart.document.formForCart.elements.length
var ID = top.cart.document.formForCart.elements›length-3!.value
var passwd = top.cart.document.formForCart.elements›length-2!.value
if (isEmpty(ID) .parallel. isEmpty(passwd)) {
alert("Your ID and/or Password is Empty |")
}
else {
if ((|isValidAlphaNum(ID) ).parallel.( |isValidAlphaNum(passwd))){
alert("check your ID and Password, Please |")
}
else {
top.cart.document.formForCart.submit( )
}
}
}
function writeSubtotal( ) {
var cart =writeHrOrBlankLine("HR")
cart += writeHrOrBlankLine(" ")
cart +="<TR>"
cart +="<TD ALIGN=LEFT> Type the tax rate into the field below.</TD>"
cart +="<TD ALIGN=RIGHT> </TD>"
cart +="<TD ALIGN=RIGHT> Subtotal </TD>"
cart +="<TD ALIGN=RIGHT><INPUT TYPE=TEST NAME=subtotal VALUE=" SIZE=10
onFocus=top.cartWarning(this)></TD>"
cart +="</TR>"
return cart
}
function writeTax( ) {
var taxRate=parseInt(0)
var numOfItemInCart=parseInt(top.cart.document.links.length)
if ( numOfItemInCart>0) {
//if tax rate is entered, retrieve it, and write it into the cart again
when update.
taxRate= top.cart.document.formForCart.elements›numOfItemInCart*3+1!.value
N
}
var cart ="<TR>"
cart +="<TD ALIGN=LEFT>Tax Rate<INPUT TYPE=TEST NAME=`taxRate`VALUE=" +
taxRate
+ " SIZE=5 onChange=top.calcTax( )>% </TD>"
cart +="<TD ALIGN=RIGHT> </TD>"
cart +="<TD ALIGN=RIGHT>Tax</TD>"
cart +="<TD ALIGN=RIGHT><INPUT TYPE=TEST NAME=tax VALUE=" SIZE=10
onFocus=top.cartWarning(this)></TD>"
cart +="</TR>"
return cart
}
function writeTotal( ) {
var cart =writeHrOrBlankLine("HR")
cart +=writeHrOrBlankLine(" ")
cart +="<TR>"
cart +="<TD ALIGN=LEFT> </TD>"
cart +="<TD ALIGN=RIGHT> </TD>"
cart +="<TD ALIGN=RIGHT> Grand Total </TD>"
cart +="<TD ALIGN=RIGHT><INPUT TYPE=TEST NAME=total VALUE=" SIZE=10
onFocus=top.cartWarning(this)></TD>"
cart +="</TR>"
return cart
}
function writeCartFooter( ) {
var yourID=" "
var yourPassword=" "
var numOfItemInCart=parseInt(top.cart.document.links.length)
if ( numOfItemInCart>0) {
//if users have entered user ID and password, keep them
yourID= top.cart.document.formForCart.elements›numOfItemInCart*3+4!.value
N
yourPassword= top.cart.document.formForCart.elements›numOfItemInCart*3+5!.
value
}
var cart =" </TABLE></CENTER>"
cart +=" <br><hr>"
cart +=" <CENTER> If you have not registered, please register first, and
then submit your order |
<br><br>"
cart +="<TABLE BORDER=0 WIDTH=`100%`>"
cart +="<TR>"
cart +="<TD ALIGN=LEFT></TD>"
cart +="<TD ALIGN=RIGHT> Your ID </TD>"
cart +="<TD ALIGN=RIGHT></TD>"
cart +="<TD ALIGN=LEFT><INPUT TYPE=`TEXT` NAME=`userID`
VALUE=.backslash.`"+yourID+".backslash.`onChange=`top.isValidAlphaNum(this
.value)`> </TD>"
cart +="</TR>"
cart += writeHrOrBlankLine(" ")
cart +="<TD ALIGN=LEFT></TD>"
cart +="<TD ALIGN=RIGHT > Your Password </TD>"
cart +="<TD ALIGN=RIGHT></TD>"
cart +="<TD ALIGN=LEFT><INPUT TYPE=`PASSWORD` NAME=`PASSWORD`
VALUE=.backslash.`"+yourPassword+".backslash.`onChange=`top.isValidAlphaNu
m(this.value)`></TD>"
cart +=" </TR>"
cart +="</TABLE><BR>"
cart +="<INPUT TYPE=`SUBMIT` VALUE=`Send This Order`
onClick=`top.isValidIDPasswd( )`></CENTER>"
cart +="</TABLE>"
cart +="</FORM>"
cart +="</BODY>"
cart +="</HTML>"
return cart
}
//totalPrice for each item = unite price*quantity
function totalPrice(thisPoint, thisForm) {
var numOfItemInCart=parseInt(top.cart.document.links.length)
if (|isValidPosInteger(thisPoint.value)) {
//invalid quantity|
thisPoint.focus( )
}
else {
for (var i = 0; i < numOfItemInCart; i++) {
if (thisPoint.name==thisForm.elements›i*3+1!.name){
//detect the quantity of which item is changed, and put order # of the
item into j.
var j=i
i=numOfItemInCart
}
}
var price= thisForm.elements›j*3!.value
price= deleteString(price, "$")
price= parseFloat(price)
var qty= thisForm.elements›j*3+1!.value
qty= parseFloat(qty)
var total=price*qty
total=formatNum(total,2)
if (total |=0.00) {
thisForm.elements›j*3+2!.value="$"+total
calcSubtotal( )
calcTax( )
calcTotal( )
}
else {
//quantity is changed to zero, delete the item from the cart.
opSwitchBoard("deleteOneItem")
}
}
}
//tax=subtotal*taxRate
function calcTax( ) {
var numOfItemInCart=parseInt(top.cart.document.links.length)
if (|isValidPosNumber (top.cart.document.formForCart.elements›numOfItemInC
art*3+1!.value
)) {
//checking if input value is valid. If invalid, the cursor will focus on
the tax rate cell
top.cart.document.formForCart.elements›numOfItemInCart*3+1!.focus( )
}
else{
//take tax rate
var taxRate= top.cart.document.formForCart.elements›numOfItemInCart*3+1!.v
alue
var value=0
value=top.cart.document.formForCart.elements›numOfItemInCart*3!.value
//take subtotal
value= deleteString(value, "$")
value= parseFloat(value)
var taxAmount =taxRate*value/100
taxAmount=formatNum(taxAmount,2)
top.cart.document.formForCart.elements›numOfItemInCart*3+2!.value
="$"+taxAmount
calcTotal( )
}
}
function calcTotal( ) {
var numOfItemInCart=parseInt(top.cart.document.links.length) //get the
total # of items in the cart
var tax= top.cart.document.formForCart.elements›numOfItemInCart*3+2!.value
//take tax
var total=top.cart.document.formForCart.elements›numOfItemInCart*3!.value
//take subtotal first
tax= deleteString(tax, "$")
total= deleteString(total, "$")
tax= parseFloat(tax)
total= parseFloat(total)
total +=tax
total=formatNum(total,2)
top.cart.document.formForCart.elements›numOfItemInCart*3+3!.value
="$"+total
}
//The variable "cartBackup" is a global variable for backup purpose when
users go to other home page,
//and return late. The variable "mySwitch" is used to decide what kind of
the operation is to execute
// according to the "mySwitch" value,
//such as "firstItem" to cart, "addOneItem", "backup", and so on. It is
also a global variable.
var cartBackup, mySwitch
function backup( ) {
mySwitch="backup"
opSwitchBoard( )
}
function reload( ) {
mySwitch="reload"
opSwitchBoard( )
}
//if "HR" is passed to this function, it write s horizontal ruler in the
cart. Otherwise, it write a blank line.
function writeHrOrBlankLine(HR) {
var leftBrace=" ", rightBrace=" "
if (HR=="HR"){
leftBrace=" <"
RightBrace">"
}
var cart =" <TR>"
cart +=" <TD COLSPAN=`4`>"
cart +=leftBrace+HR+rightBrace+"</TD>"
cart +="</TR>"
return cart
}
//this function create a web page for a search engine on the fly.
function writeSearchEngine( ){
var engine="<HTML><HEAD><TITLE>Search Engine</TITLE></HEAD>"
engine+="<BODY>"
engine+="<CENTER>"
engine+="<H2>The Search Engine</H2>"
engine+="<HR>"
engine+="<H4> Enter the name of the item you want. Then click the `Seach
the Store|`button.</H4>"
engine+="<P><P>"
engine+="<FORM method post action= >"
engine+="<INPUT TYPE=`text` NAME=`query` SIZE=`40`
onChange=`top.isValidAlpha(this.value)`><P>"
engine+=" <INPUT TYPE=`RESET` VALUE=`Clear Up`>"
engine+=" <INPUT TYPE=`SUBMIT` VALUE=`Seach the Store|`
onClick=`top.isValidAlpha(query.value)`>"
|
Same subclass Same class Consider this |
||||||||||
