djcochran Posted May 3, 2009 Share Posted May 3, 2009 I recently converted all my html pages into php pages, and in doing so, well...I can't seem to figure out how to get the javascript function checkout() to work at all! It used too...now it doesn't. I know this may be a lot to go through, but if anyone would mind looking through and maybe seeing what could be the problem? Thanks! <?php session_start(); $file = fopen("template2.data", "r"); while(!feof($file)) { $line = fgets($file); if(preg_match("/@@CONTENT_HERE@@/", $line, $dummyarray)){ print<<<END <script type="text/javascript"> function changeLink(targetDiv){ targetDiv.style.color = "#FFFF00"; } function revertLink(targetDiv){ targetDiv.style.color = "blue"; } </script> <script type="text/javascript"> function set_cookie (name, value, exp_y, exp_m, exp_d, path, domain, secure){ var cookie_string = name + "=" + escape (value); if (exp_y){ var expires = new Date ( exp_y, exp_m, exp_d ); cookie_string += "; expires=" + expires.toGMTString(); } if(path){ cookie_string += "; path=" + escape (path); } if(domain){ cookie_string += "; domain=" + escape (domain); } if (secure){ cookie_string += "; secure"; } document.cookie = cookie_string; } </script> <script type="text/javascript"> function checkOut(){ var cartContentDisplay = "Shopping Cart Contents:\n" var cookieArray=document.cookie.split(';'); var cookieIndex=0; for(var i=1; i<cookieArray.length;++i){ var cookiePair=cookieArray[i].split('='); cartContentDisplay = cartContentDisplay + "\nProduct Number: " +cookiePair[cookieIndex] +"\nQuantity: " +cookiePair[cookieIndex+1] +"\n\n"; } alert(cartContentDisplay); } </script> <script type="text/javascript"> var quantityRe = /^\d+$/; function quantityAdd(){ var answer=confirm("Update shopping cart?") if(answer==true){ var fieldArray=document.products.getElementsByTagName("input"); for(i=0; i < fieldArray.length; ++i){ if(fieldArray[i].type=="text"){ if(!quantityRe.test(fieldArray[i].value) && fieldArray[i].value != ""){ alert("Please check the input for item #" + fieldArray[i].name); return; } } } for(j=0; j < fieldArray.length; ++j){ if(fieldArray[j].type=="text"){ if(fieldArray[j].value == ""){ fieldArray[j].value = 0; } document.cart.cartTotal.value = eval(document.cart.cartTotal.value) + eval(fieldArray[j].value); var totalCartContents=get_cookie("cartTotal"); set_cookie("cartTotal", totalCartContents+eval(fieldArray[j].value)); if(fieldArray[j].value > 0){ var currentCartContents = get_cookie(fieldArray[j].name); set_cookie(fieldArray[j].name, eval(fieldArray[j].value)+currentCartContents); } } } } else{} for(k=0; k < fieldArray.length; ++k){ if(fieldArray[k].type=="text"){ fieldArray[k].value = 0; } } } </script> <script type="text/javascript"> function get_cookie(cookie_name){ var results = document.cookie.match ( '(^| ?' + cookie_name + '=([^;]*)(;|$)' ); if(results) return eval((unescape(results[2]))); else return null; } </script> <DIV CLASS="body"> <FORM NAME="products"> <TABLE BORDER="1"> <TR> <TD WIDTH="50px" HEIGHT="50px"><IMG WIDTH="175px" HEIGHT="175px" SRC="picscript.php?pnum=10117"></TD> <TD WIDTH="1500px" HEIGHT="50px"> Product Name: Slinky <BR><I>The greatest toy ever created. Try flipping it down the stairs for extra excitement!</I> <BR><BR>Price: <FONT COLOR="#FF3300">$1.99 </FONT> + S/H <BR>Number in Stock: 1000 <BR>Product #10117 <BR><P ALIGN="RIGHT">Quantity: <INPUT TYPE="text" NAME=10117 MAXLENGTH="5" STYLE="width:40px;" VALUE="0" CLASS="textfield"></P> </TD> </TR> <TR> <TD WIDTH="50px" HEIGHT="50px"><IMG WIDTH="175px" HEIGHT="175px" SRC="images/10123.jpg"></TD> <TD WIDTH="1500px" HEIGHT="50px"> Product Name: The Blaze Broom <BR><I>Sweep your kitchen with the speed of Blaze®!</I> <BR><BR>Price: <FONT COLOR="#FF3300">$9.99 </FONT> + S/H <BR>Number in Stock: 23 <BR>Product #10123 <BR><P ALIGN="RIGHT">Quantity: <INPUT TYPE="text" NAME=10123 MAXLENGTH="5" STYLE="width:40px;" VALUE="0" CLASS="textfield"></P> </TD> </TR> <TR> <TD WIDTH="50px" HEIGHT="50px"><IMG WIDTH="175px" HEIGHT="175px" SRC="images/10543.jpg"></TD> <TD WIDTH="1500px" HEIGHT="50px"> Product Name: A White T-Shirt <BR><I>100% natural cotton. The perfect thing to wear whenever you don't have anything else to wear!</I> <BR><BR>Price: <FONT COLOR="#FF3300">$5.99 </FONT> + S/H <BR>Number in Stock: 54 <BR>Product #10543 <BR><P ALIGN="RIGHT">Quantity: <INPUT TYPE="text" NAME=10543 MAXLENGTH="5" STYLE="width:40px;" VALUE="0" CLASS="textfield"></P> </TD> </TR> <TR> <TD WIDTH="50px" HEIGHT="50px"><IMG WIDTH="175px" HEIGHT="175px" SRC="images/10225.jpg"></TD> <TD WIDTH="1500px" HEIGHT="50px"> Product Name: Porcelain German Shepherd <BR><I>The perfect addition to any bookshelf.</I> <BR><BR>Price: <FONT COLOR="#FF3300">$19.99 </FONT> + S/H <BR>Number in Stock: 3 <BR>Product #10225 <BR><P ALIGN="RIGHT">Quantity: <INPUT TYPE="text" NAME=10225 MAXLENGTH="5" STYLE="width:40px;" VALUE="0" CLASS="textfield"></P> </TD> </TR> <TR> <TD WIDTH="50px" HEIGHT="50px"><IMG WIDTH="175px" HEIGHT="175px" SRC="images/10318.jpg"></TD> <TD WIDTH="1500px" HEIGHT="50px"> Product Name: Nintendo Entertainment System <BR><I>Technology meets fun! Game cartridges not included.</I> <BR><BR>Price: <FONT COLOR="#FF3300">$39.99 </FONT> + S/H <BR>Number in Stock: 10 <BR>Product #10318 <BR><P ALIGN="RIGHT">Quantity: <INPUT TYPE="text" NAME=10318 MAXLENGTH="5" STYLE="width:40px;" VALUE="0" CLASS="textfield"></P> </TD> </TR> <TR> <TD WIDTH="50px" HEIGHT="50px"><IMG WIDTH="175px" HEIGHT="175px" SRC="images/10505.jpg"></TD> <TD WIDTH="1500px" HEIGHT="50px"> Product Name: Grab Bag <BR><I>A mysterious assortment of odds and ends. Great for parties!</I> <BR><BR>Price: <FONT COLOR="#FF3300">0.99 </FONT> + S/H <BR>Number in Stock: 9999 <BR>Product #10505 <BR><P ALIGN="RIGHT">Quantity: <INPUT TYPE="text" NAME=10505 MAXLENGTH="5" STYLE="width:40px;" VALUE="0" CLASS="textfield"></P> </TD> </TR> <TR> <TD WIDTH="50px" HEIGHT="50px"><IMG WIDTH="175px" HEIGHT="175px" SRC="images/10353.jpg"></TD> <TD WIDTH="1500px" HEIGHT="50px"> Product Name: SuperMote <BR><I>Never hit the wrong button ever again with ridiculously large remote control. A great gift for old people!</I> <BR><BR>Price: <FONT COLOR="#FF3300">$12.99 </FONT> + S/H <BR>Number in Stock: 49 <BR>Product #10353 <BR><P ALIGN="RIGHT">Quantity: <INPUT TYPE="text" NAME=10353 MAXLENGTH="5" STYLE="width:40px;" VALUE="0" CLASS="textfield"></P> </TD> </TR> <TR> <TD WIDTH="50px" HEIGHT="50px"><IMG WIDTH="175px" HEIGHT="175px" SRC="images/10369.jpg"></TD> <TD WIDTH="1500px" HEIGHT="50px"> Product: Shower Caps (AMOUNT-GROSS) <BR><I>One order of these caps can last you a lifetime! Comes in three fun colors!</I> <BR><BR>Price: <FONT COLOR="#FF3300">$2.99 </FONT> + S/H <BR>Number in Stock: 144000 <BR>Product #10369 <BR><P ALIGN="RIGHT">Quantity: <INPUT TYPE="text" NAME=10369 MAXLENGTH="5" STYLE="width:40px;" VALUE="0" CLASS="textfield"></P> </TD> </TR> <TR> <TD WIDTH="50px" HEIGHT="50px"><IMG WIDTH="175px" HEIGHT="175px" SRC="images/10875.jpg"></TD> <TD WIDTH="1500px" HEIGHT="50px"> Product Name: Sonic Earz <BR><I>You will be able to hear a gnat pass gas with these ultra-powered hearing enhancers!</I> <BR><BR>Price: <FONT COLOR="#FF3300">$49.99 </FONT> + S/H <BR>Number in Stock: 20 <BR>Product #10875 <BR><P ALIGN="RIGHT">Quantity: <INPUT TYPE="text" NAME=10875 MAXLENGTH="5" STYLE="width:40px;" VALUE="0" CLASS="textfield"></P> </TD> </TR> <TR> <TD WIDTH="50px" HEIGHT="50px"><IMG WIDTH="175px" HEIGHT="175px" SRC="images/10299.jpg"></TD> <TD WIDTH="1500px" HEIGHT="50px"> Product Name: The Swiss Mister Pro <BR><I>Contains every tool for every situation.</I> <BR><BR>Price: <FONT COLOR="#FF3300">$129.99 </FONT> + S/H <BR>Number in Stock: 20 <BR>Product #10299 <BR><P ALIGN="RIGHT">Quantity: <INPUT TYPE="text" NAME=10299 MAXLENGTH="5" STYLE="width:40px;" VALUE="0" CLASS="textfield"></P> </TD> </TR> </TABLE> <P ALIGN="RIGHT"><INPUT TYPE="button" NAME="addButton" ONCLICK="javascript:quantityAdd()" VALUE="Add to Shopping Cart"><INPUT TYPE="button" NAME="checkoutButton" ONCLICK="javascript:checkOut()" VALUE="Checkout"></P> <BR><BR> </FORM> </DIV> END; }else if(preg_match("/@@LOGGED_IN@@/", $line, $dummyarray)){ // look for another special marker if(isset($_SESSION['name'])){ // check if session variable that indicate user is logged in has been set echo "        User is logged in"; }else{ echo "        User is not logged in"; } }else{ echo $line; }; // end else }; // end while ?> Link to comment https://forums.phpfreaks.com/topic/156604-javascript-problem/ Share on other sites More sharing options...
Ken2k7 Posted May 3, 2009 Share Posted May 3, 2009 You know there's a JavaScript forum, right? Are you saying the function doesn't run or it's getting wrong values? Link to comment https://forums.phpfreaks.com/topic/156604-javascript-problem/#findComment-824573 Share on other sites More sharing options...
djcochran Posted May 3, 2009 Author Share Posted May 3, 2009 I guess it won't run at all. Like...when I click the 'Checkout' button...the alert message doesn't appear. Link to comment https://forums.phpfreaks.com/topic/156604-javascript-problem/#findComment-824597 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.