Старик рад, что в разноголосице есть пару движений ответить фалангами. Я то длиннющий, древний как мир энтузиастов javascript выложу. Глянешь? Прямо трабл какой то вдруг | Код | function makeArray(n){ this.length = n; for(var i = 1; i <= n; i++){ this[i] = 0; } return this; }
var orderNum = 0; var order = new makeArray(100); var indexNum = 0; var count; var formSave;
function currency(money){ money = money + "" var monLen = money.length; var digPos = money.indexOf("."); if(digPos == -1 & monLen < 1){ money = money.substring(0,digPos+ 1) + "00"; } else if(digPos == -1 & monLen > 0){ return money; }else{ cents = money.substring(digPos + 1, monLen + 1); if(cents.length == 1){ money = money + "0"; }else if(cents.length > 2){ roundVal = cents.charAt(2); if(roundVal >= 5){ money = parseFloat(money) + .01; money = money + ""; money = money.substring(0,digPos + 3) }else{ money = money.substring(0,digPos + 3) } } } return money; }
function showProd(form){ var iter = 0; var match = false; var oldlen = 1; count = 0; sWin = parent.frames[2].document prodName = parent.frames[3].document.searcher.lookup.value; sWin.open(); sWin.write("<HTML><HEAD><TITLE>"+ prodName + " </TITLE></HEAD>"); sWin.write("<BODY bgcolor=#ffffff text=#000000>"); for (var i = 1; i <= prodID.length; i++){ //alert(theProd + " " + prodID[i].name.toUpperCase()); if(prodName.toUpperCase() == prodID[i].name.toUpperCase()){ indexNum = i; prodID[i].show(sWin,i); match = true; } } if(!match){ pTotal = new makeArray(prodID.length); for (var i = 1; i <= prodID.length; i++){ var pSearch = prodName.toUpperCase(); var pInventory = prodID[i].name.toUpperCase(); for(var x = 1; x <= pSearch.length; x++){ if(pSearch.substring(0,x) == pInventory.substring(0,x)){
pTotal[i] = pSearch.substring(0,x); } } } for (var i = 1; i <= prodID.length; i++){ // alert(pTotal[i] + " " + i); if(pTotal[i] != "0"){ if(pTotal[i].length >= oldlen){ oldlen = pTotal[i].length; olditer = iter; var iter = i; } } } if(oldlen > 1){ sWin.write("<b>Nearest match was:</b><br> ") indexNum = iter; prodID[iter].show(sWin,iter); if(olditer != 0){ sWin.write("<br><b>Next closest match was:</b><br> ")
indexNum = olditer; prodID[olditer].show(sWin,olditer); } }else{ sWin.write("No match!"); } } sWin.write("</BODY></HTML>"); sWin.close(); }
function searchType(form){ count = 0; prodTypeInfo = form; var match = false; tWin = parent.frames[2].document tWin.open(); tWin.write("<HTML><HEAD><TITLE>"+ prodTypeInfo + " </TITLE></HEAD>");
tWin.write("<BODY bgcolor=#ffffff text=#000000> "); for (var i = 1; i <= prodID.length; i++){ if(prodTypeInfo == prodID[i].type){ indexNum = i; prodID[i].show(tWin,i); match = true; } } tWin.write("</BODY></HTML>"); tWin.close(); }
function product (name,description,image,price,type,link,url){ this.name = name; this.description = description; this.image = image this.price = price; this.type = type; this.show = show; if(link != ""){ this.link = "<center><TABLE BORDER=0><TR><TD><A HREF='" + url + "'><Font face=arial size=-2>" + link + "</font></A></TD></TR></TABLE></center>"; }else{ this.link = ""; } } function show(w,prodIndexNum){ w.write("</CENTER><center><TABLE BORDER = 0 WIDTH=300><TR><TD BGCOLOR=#d5d5ff><FONT FACE = 'arial' color=blue><b>" + this.name + "</b></FONT></TD></TR></TABLE></center>");
if(this.image.length > 1){ w.write("<CENTER><TABLE BORDER=0 COLS=2 WIDTH=300 BGCOLOR=#FFCC00 ><TR BGCOLOR=#00CC00><TD><FONT FACE = 'Arial' SIZE = 2 >Image</FONT></TD><TD><FONT FACE = 'Arial' SIZE = 2 >Description</FONT></TD></TR><TR><TD><IMG SRC='" + this.image + "'></TD>"); w.write("<TD><FONT FACE = 'Arial' SIZE = 2 >" + this.description + "</TD></TR></Table></CENTER>"); } if(this.link != ""){ w.write(this.link); }
w.write("<FORM>"); //alert(prodIndexNum); orderProd(this,w,prodIndexNum); w.write("</FORM><HR SIZE=1 NOSHADE WIDTH=90%><br>"); // w.write(" <INPUT TYPE = 'button' VALUE = 'Go Back' onClick = history.go(-1)>");
}
function orderProd(obj,win,index){
win.write("<CENTER><TABLE BORDER=0 COLS=2 WIDTH=300 BGCOLOR=#CCCCCC><TR><TD><FONT FACE = 'arial' size=-1><b>Price Each: $</b>" + obj.price+"</font></CENTER>"); win.write(" <FONT FACE = 'arial' size=-1><b>Enter Quantity:</b></font> " + "<INPUT TYPE = 'text' SIZE = 3 NAME = 'q' VALUE = '1' onBlur = parent.reTotal("+ parent.count + "," + obj.price + ") onFocus = parent.reTotal("+ parent.count + "," + obj.price + ")><br>");
win.write(" <FONT FACE = 'arial' size=-1><b>Total:" + " $</b></font><INPUT TYPE = 'text' SIZE=7 NAME= subTotal VALUE =" + obj.price + "> " + "<INPUT TYPE ='button' VALUE = 'SubTotal' onClick = parent.reTotal("+ parent.count + "," + obj.price + ")></TR></TABLE></CENTER>");
win.write("<CENTER><IMG SRC=pickit.gif ALIGN=TEXTTOP><INPUT TYPE = 'button' VALUE = ' Put in Basket ' onClick = parent.add(" + parent.count + "," + index + ")>")
count++; }
function add(id, oIndex){ var theForm = parent.frames[2].document.forms[id]; productName = prodID[oIndex].name; totalSum =parent.frames[2].document.forms[id].subTotal.value; totalQuanity = parent.frames[2].document.forms[id].q.value; if(totalQuanity == 0){ alert("You entered a quantity of 0!\n We cannot process this order");
parent.frames[2].document.forms[id].q.value = 1; reTotal(id,prodID[oIndex].price); }else{ if( confirm("You are adding " + totalQuanity + " order/s of " + productName + " \n Subtotal: " + totalSum + " to your shopping cart.")){
store(oIndex,totalSum,totalQuanity); }else{ alert("\n\nThis order was not placed in your shopping cart."); } } }
function store(o,ts,tq){ orderNum++; order[orderNum] = new cartGoods(o,ts,tq); showTotal = 0; for(var i = 1; i <= orderNum;i++){ showTotal += parseFloat(order[i].totSum); } parent.frames[1].document.forms[0].runningTotal.value = currency(showTotal);
} { request.setCharacterEncoding("UTF-8"); } catch (java.io.UnsupportedEncodingException e) { log.error("doSelectLanguage() : request.setCharacterEncoding() : UnsupportedEncodingException", e); } // SET LOCALE BASED ON LANGUAGE java.util.Locale locale = new java.util.Locale(lang); response.setLocale(locale); response.setContentType("text/html; charset=UTF-8");
function cartGoods(Indx, totSum, totQ){ this.Indx = prodID[Indx].name; this.totSum = totSum; this.totQ = totQ; }
function view(){ vWin = parent.frames[2].document; vWin.open(); vWin.write("<HTML><BODY BGCOLOR=#ffffd8 text=#000000><CENTER>"); if(orderNum != 0){ vWin.write("<FONT FACE='Arial' Size=5>" + "Your Shopping Basket Contents</FONT><br><br>");
vWin.write("<FORM><TABLE BORDER=1>"); vWin.write("<TH COLSPAN=1 BGCOLOR='#f7efde'>Quantity</TH>"); vWin.write("<TH COLSPAN=1 BGCOLOR='#f7efde'>Product</TH>"); vWin.write("<TH COLSPAN=1 BGCOLOR='#f7efde'>Price</TH>"); vWin.write("<TH COLSPAN=1 BGCOLOR='#f7efde'><FONT FACE='Arial' SIZE=2> </TH>");
for(var i = 1; i <= orderNum; i++){ vWin.write("<TR><TD COLSPAN=1 bgcolor='#00ffff' ALIGN=CENTER>" + "<FONT FACE='Arial' SIZE=3>" + order[i].totQ + "</FONT></TD>");
vWin.write("<TD COLSPAN=1 bgcolor='#00ffff' ><FONT FACE='Arial' SIZE=3>" + order[i].Indx + "</FONT></TD>");
vWin.write("<TD COLSPAN=1 bgcolor='#00ffff' ><FONT FACE='Arial' SIZE=3>" + currency(order[i].totSum) + "</FONT></TD>");
vWin.write("<TD VALIGN=TOP ALIGN=CENTER bgcolor='#00ffff' >" + "<INPUT TYPE = 'checkbox' NAME = checkbox" + i + " onclick = parent.remove(" + i + ")></FONT>");
vWin.write("<FONT FACE='Arial' SIZE=1><b>To remove check the" + " checkbox</b></FONT></TD></TR>");
} vWin.write("</TABLE></FONT></FORM>"); }else{ vWin.write("<FONT SIZE = 5 FACE = 'arial'><br>" + "<br>Your shopping cart is empty!</FONT>"); if(navigator.appName.indexOf("Netscape") != -1){ vWin.write("<FORM><INPUT TYPE='button' VALUE='Back to Order Form' onclick='history.go(-1)'>"); } } vWin.write("</TABLE></FONT></FORM></BODY></HTML>"); vWin.close(); }
function remove(item){ var newSum = 0; for(var i = item+1; i <= orderNum; i++){ if(item == orderNum){ order[i].Indx = ""; order[i].totSum = 0; order[i].totQ = ""; break; }else{ order[i-1].Indx = order[i].Indx; order[i-1].totSum = order[i].totSum; order[i-1].totQ = order[i].totQ; } } orderNum--; for(var i = 1; i <= orderNum;i++){ newSum += parseFloat(order[i].totSum); } parent.frames[1].document.forms[0].runningTotal.value = currency(newSum);
view();
}
function checkOut(){ if(orderNum != 0){ cWin = parent.frames[2].document; cWin.open(); cWin.write("<HTML><BODY BGCOLOR=#ffffd8 text=#000000><CENTER>"); cWin.write("<FONT FACE='Arial' Size=5>Your Shopping Basket</FONT>" + "<TABLE BORDER=1><TR>");
grandTotal = 0; // cWin.write("<FORM NAME = 'orderform'>"); cWin.write("<TH COLSPAN=1 BGCOLOR='#f7efde'>Quanity</TH>"); cWin.write("<TH COLSPAN=1 BGCOLOR='#f7efde'>Product</TH>"); cWin.write("<TH COLSPAN=1 BGCOLOR='#f7efde'>Price</TH>"); cWin.write("<TH COLSPAN=1 BGCOLOR='#f7efde'>Total Price</TH></TR>"); for(var i = 1; i <= orderNum; i++){ cWin.write("<TR><TD COLSPAN=1 bgcolor='#00ffff' ALIGN=CENTER>" + "<Font Face = 'Arial' Size = 2>" + order[i].totQ + "</TD> ");
cWin.write("<TD COLSPAN=1 bgcolor='#00ffff' ALIGN=CENTER>" + "<Font Face = 'Arial' Size = 2>" + order[i].Indx + "</TD>");
cWin.write("<TD COLSPAN=1 bgcolor='#00ffff'' ALIGN=CENTER>" + "<Font Face = 'Arial' Size = 2>" + parent.currency(order[i].totSum/order[i].totQ) + "</TD>" );
cWin.write("<TD COLSPAN=1 bgcolor='#00ffff' ALIGN=CENTER>" + "<Font Face = 'Arial' Size = 2>" + parent.currency(order[i].totSum) + "</TD></TR>" );
grandTotal += parseFloat(order[i].totSum); } finalSum = currency((grandTotal * .08) + grandTotal); cWin.write("<TD COLSPAN=3 ALIGN=CENTER bgcolor='#f7efde'><b>Total:</b></TD>");
cWin.write("<TD COLSPAN=1 ALIGN=CENTER bgcolor='#f7efde'><b>$ " + finalSum + " </b><SMALL>(includes tax)</SMALL></TD>");
cWin.write("</TR></TABLE></CENTER>"); // cWin.write("<br><br><b>Total: $" + finalSum + " </b>(includes CA tax)<b>");
cWin.write("</b><br><br>If this is correct please fill out and submit the form below.<br>");
cWin.write("If there is an error in your order or something you wish" + " to change, click \"View Cart\" to make the changes.<br>");
// ATTENTION NETSCAPE USER: // PLEASE CHANGE THE E-MAIL ON THE NEXT LINE TO YOUR OWN VALID E-MAIL! cWin.write(" <FORM NAME = orderform METHOD = POST ENCTYPE=text/plain ACTION=mailto:[email protected]>"); cWin.write("Email:<INPUT TYPE='text' SIZE=20 NAME='email'><br>"); cWin.write("NAME:<INPUT TYPE = 'text' SIZE = 50 NAME = 'orderee'><br>");
cWin.write("Street Address: <INPUT TYPE = 'text' SIZE = 43 NAME = 'address'><br>");
cWin.write("City: <INPUT TYPE = 'text' SIZE = 52 NAME = 'city'><br>");
cWin.write("State:<INPUT TYPE = 'text' SIZE = 2 NAME = 'state'> ");
cWin.write("Zip Code: <INPUT TYPE = 'text' SIZE = 5 NAME = 'zip'><br><br>");
cWin.write("Shipping Method:<SELECT NAME = 'shipSelection' onChange = 'parent.shipping(this.form," + finalSum + ")'>");
// EDIT HERE IF YOU WANT TO CHANGE YOUR SHIPPING METHOD!
cWin.write("<OPTION VALUE = '0'>Select Method"); cWin.write("<OPTION VALUE = '20.95'>Same Day"); cWin.write("<OPTION VALUE = '10.95'>Next Day"); cWin.write("<OPTION VALUE = '7.95'>2nd Day"); cWin.write("<OPTION VALUE = '3.95'>3 Day</SELECT><br><br>"); cWin.write("Purchase Total = $<INPUT TYPE = 'text' SIZE = 15 NAME = 'finalTot'> includes CA tax & shipping<br>");
cWin.write("Credit Card #: <INPUT TYPE = 'text' SIZE = 19 NAME = 'ccNum'><br>");
cWin.write("Expiration Date: <INPUT TYPE = 'text' SIZE = 17 NAME = 'exDate'><br><br>");
cWin.write(" <INPUT TYPE = 'hidden' NAME='order'" + " VALUE = ''>");
cWin.write("<CENTER><INPUT TYPE = 'submit' VALUE = 'Submit Order' onClick = 'parent.formData(this.form)'>");
cWin.write(" <INPUT TYPE = 'reset' VALUE = 'Reset'>"); cWin.write("</FORM>"); cWin.write("</b></FONT></CENTER></BODY></HTML>"); cWin.close(); }else{ alert("\n\nYour shopping cart is empty!\n\n"); } }
function formData(form){
var formElems = form.elements.length; formSave = new makeArray(formElems-3); for(var i = 1; i <= formElems; i++){ formSave[i] = form.elements[i-1].value; } for(var i = 1; i <= orderNum; i++){ form.elements[10].value += "Quanity:" + order[i].totQ form.elements[10].value += " " + order[i].Indx form.elements[10].value += " at " + order[i].totSum/order[i].totQ + " | " } if(navigator.appName.indexOf("Netscape") != -1){ setTimeout(location.href="thankyou.htm",2000) form.submit(); }else{ alert("Submitting of form with mailto tag is only possible in Netscape Navigator!") return false; } }
function reTotal(c,totalPrice){ totalPrice = totalPrice * parent.frames[2].document.forms[c].q.value;
newTotal = currency(totalPrice) parent.frames[2].document.forms[c].subTotal.value = newTotal; }
function shipping(form, fSum){ shipCost = form.shipSelection.options[form.shipSelection.selectedIndex].value;
form.finalTot.value =currency( parseFloat(shipCost) + parseFloat(fSum));
}
function empty(){ if(orderNum == 0){ alert("\n\nYour cart is already empty!\n\n"); }else{ orderNum = 0; alert("\nYour cart has been emptied!\n"); } }
|
хороший писатель Даниил Хармс
|