JavaScript - Business Catalyst Checkout Javascript
Hi Guys,
At the moment we are running the below javascript on the shopping cart page of a website to stop customers purchasing under $500 worth of products. What we need is for the javascript to recognised a discount code entered and allow for purchases under $500 or to recognised a particular password or login used by a special user and then allow them to purchase under $500. We tried to put an 'else if' under the 'if (intotal > 500) { window.location=document.getElementById('catshopbuy').href; }' and added a variable for the discout code on the <td> tag but this broke the shop and we could not checkout at all. We also created and 'if' statement around the below code and said if the discount code was equal to the code we setup then ignore all the below script but this didnt work either. Is this the correct way to go about it, are we missing something or is there an easier way to accomplish this? Code: <script> function stay() { var intotal=document.getElementById('intotal').innerHTML; erro=0; var k=document.getElementById("ShippingOptions"); if(k){if(k.value<1){document.getElementById('error_msg').innerHTML=Oshoplang.InvalidShip;erro=1;}} var c=document.getElementById("shippingCountry");ccVal="";if(c){ccVal=c.value}var a=document.getElementById("shippingState");var l="";if(a){l=a [a.selectedIndex].text;if(a.value<1){document.getElementById('error_msg').innerHTML=Oshoplang.ChooseState;erro=1;}} var j=document.getElementById("shippingPostcode");var h="";if(j){h=j.value;if(j.value.length<1){document.getElementById ('error_msg').innerHTML=Oshoplang.EnterZip;erro=1;}} var g=document.getElementById("shippingCalc");if(g){var b=false;var e=g.getElementsByTagName("input");if(e.length>0){for(var d=0;d<e.length;d++){if(e [d].checked){b=true;break}}}if(!b){document.getElementById('error_msg').innerHTML=Oshoplang.ChooseShip;erro=1;}} if (erro==1) {document.getElementById('error_msg').style.display="block";} if (erro==0) { intotal=parseFloat(intotal.substring(1).replace(/,/gi,"") ); if (intotal > 500) { window.location=document.getElementById('catshopbuy').href; } else { document.getElementById('error_msg').innerHTML="ERROR - THE TOTAL AMOUNT OF YOUR ORDER IS BELOW $500"; document.getElementById('error_msg').style.display="block"; } } } </script> Any guidance would be great. Thanks Rachael Similar TutorialsSo I have my form built and all but I need to add the total cost of the items selected now. I'm not sure how to get the elements in the form and store them in a variable. Like for the single, that should have the value of $2. How can I get that and store it in a var? Here is the html: Code: <html> <head> <style type="text/css"> #sizeOf { border-style: solid; border-width:5px; border-color:red; } #top { border-style: solid; border-width:5px; border-color:red; } #price { border-style: solid; border-width: 5px; border-color:red; } #ta { border-style:solid; border-width: 5px; border-color:black; } <script type="text/javascript" src="cost.js"> </script> </style> </head> <body> <center> <h1> Joe's Famous Burgers <h1> <br /> <h1> On-Line Order Form </h1></center> <center> <form id="sizeOf" name="size"> <p> Select the size burger you want</p> <label> <input type="radio" id="siingle" name="size" value="2.00" /> Single - $2.00</label> <label> <input type="radio" id="double" name="size" value="3.00" /> Double - $3.00</label> <label> <input type="radio" id="triple" name="size" value="4.00" /> Triple- $4.00</label> </form> </center> <br /> <center> <form id="top" name="toppings"> <p> Select the toppings: </p> <label> <input type ="checkbox" name="cbox" value="cheese" /> Cheese ($0.50) </label> <label> <input type ="checkbox" name="cbox" value="onions" /> Onions ($0.25) </label> <label> <input type ="checkbox" name="cbox" value="lettuce" /> Lettuce (FREE) </label> <br /> <br /> <label> <input type ="checkbox" name="cbox" value="tomatoes" /> Tomatoes ($0.30) </label> <label> <input type ="checkbox" name="cbox" value="mustard" /> Mustard (FREE) </label> <label> <input type ="checkbox" name="cbox" value="cheeseOnly" /> Cheese ONLY($0.40) </label> </form> </center> <center> <form id="price" name="total"> <p> <h3> To obtain the price of your order click on the price button below: </h3></p> <input type="submit" value="Price (Submit Button)" onClick="computeCost();"/> <input type="submit" value="Clear Form" /> <br /> <br /> <textarea id="ta" rows="10" cols="50"> </textarea> </form> </center> </center </body> </html> Here is the js: Code: //cost.js function computeCost(){ var single = document.getElementId("single").value; var double = document.getElementId("double").value; var triple = document.getElementId("triple").value; document.write("<p>" + single + "gfgdgfd" + "</p>"); } I have now resolved please delete.
I downloaded this Free Shopping Cart in Java Script some months ago, I've been struggling for weeks to get it to work 100% - without success the support forum linked to the homepage has been inactive for years and seems to be dead. This script is totally perfect for our webshop, clean and simple and not a burden on the server, everything seems to work perfectly except for 1 problem... The sendmail function will not work! We desperately need to find a solution to this problem as soon as possible since we're losing orders everyday our webshop is offline. Any help in finding the source of the problem would be very much appreciated! The problem must be in either the checkout.pl file Code: #!/usr/bin/perl require 5.001; $header = "/cgi-bin/header.html"; $footer = "cgi-bin/footer.html"; $mailprogram = "/usr/lib/sendmail"; $returnpage = "/"; $youremail = "myname\@mydomain.com"; $csvfilename = "/cgi-bin/orders.csv"; $csvquote = "\"\""; $mode = "FILE"; #These are required fields. I recommend enforcing these by javascript, #but let's just make sure here as well. @required = ( 'b_first', 'b_last', 'b_addr', 'b_city', 'b_state', 'b_zip', 'b_phone', 'b_email' ); sub urlDecode { my ($string) = @_; $string =~ tr/+/ /; $string =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex($1))/eg; $string =~ s/['"]/\'/g; return ($string); } sub processCGI { local ($cgiData, $key, $value, $pair, @pairs); if ($ENV{'REQUEST_METHOD'} eq 'GET') { $cgiData = $ENV{'QUERY_STRING'}; } else { $cgiData = <STDIN>; } @pairs = split (/&/, $cgiData); foreach $pair (@pairs) { ($key, $value) = split (/\=/, $pair); $key = &urlDecode($key); $value = &urlDecode($value); if(defined ${$key}){ ${$key} .= ", ".$value; }else{ ${$key} = $value; } } } sub doFormError { my ($errString) = @_; open (HEAD, $header); @LINES = <HEAD>; close HEAD; print "Content-type: text/html\n\n"; print @LINES; print "<FONT SIZE=+2>The form you submitted was not complete.<BR><BR></FONT>"; print "$errString<BR><BR>\n"; print "<INPUT TYPE=BUTTON ONCLICK='history.back()' VALUE=' Return to the checkout page '><HR>"; open (FOOT, $footer); @LINES = <FOOT>; close FOOT; print @LINES; exit; } sub doError { my ($errString) = @_; print "Content-type: text/html\n\n"; open (HEAD, $header); @LINES = <HEAD>; close HEAD; print @LINES; print "$errString<BR><BR>\n"; open (FOOT, $footer); @LINES = <FOOT>; close FOOT; print @LINES; exit; } sub invalidE { my ($szEmail) = @_; my ($user, $host); $szEmail =~ tr/A-Z/a-z/; if ($szEmail =~ /\s/) { return 1; } ($user, $host) = split (/\@/, $szEmail); if ($host =~ /compuserve/i) { ; } else { if (! $user =~ /\D/) { return 1; } if (! $host =~ /\D/) { return 1; } if (substr ($user,0,1) !~ /[a-z]/) { return 1; } } if ($szEmail =~ /\w+\@[\w|\.]/) { return 0; } else { return 1; } } sub populateDateVar { @months = (); push(@months,"January"); push(@months,"February"); push(@months,"March"); push(@months,"April"); push(@months,"May"); push(@months,"June"); push(@months,"July"); push(@months,"August"); push(@months,"September"); push(@months,"October"); push(@months,"November"); push(@months,"December"); @days = (); push(@days,"Sunday"); push(@days,"Monday"); push(@days,"Tuesday"); push(@days,"Wednesday"); push(@days,"Thursday"); push(@days,"Friday"); push(@days,"Saturday"); ($sec,$min,$hour,$day,$month,$year,$day2) = (localtime(time))[0,1,2,3,4,5,6]; if ($sec < 10) { $sec = "0$sec"; } if ($min < 10) { $min = "0$min"; } if ($hour < 10) { $hour = "0$hour"; } if ($day < 10) { $day = "0$day"; } $year += "1900"; #$todaysdate = "$months[$month] $day, $year $hour:$min:$sec"; } # process the form input. &processCGI; &populateDateVar; foreach $check(@required) { unless ($check) { doFormError("It appears that you forgot to fill in the <strong>$check</strong> field."); exit; } } # checks for valid email address if( &invalidE($b_email) ){ doFormError('You submitted an invalid email address.'); } if( $mode eq "BOTH" || $mode eq "EMAIL") { # Send email order to you... open (MAIL,"|$mailprogram"); print MAIL "To: $youremail\n"; print MAIL "From: $b_email\n"; print MAIL "Subject: New Online Order\n"; print MAIL "\n\n"; print MAIL "A new order has been received. A summary of this order appears below.\n"; print MAIL "\n"; print MAIL "Order Date: $months[$month] $day, $year $hour:$min:$sec \n"; print MAIL " \n"; print MAIL "Bill To: \n"; print MAIL "-------- \n"; print MAIL " $b_first $b_last \n"; print MAIL " $b_addr \n"; print MAIL " $b_addr2 \n"; print MAIL " $b_city, $b_state $b_zip \n"; print MAIL " $b_phone \n"; print MAIL " $b_fax \n"; print MAIL " $b_email \n"; print MAIL " \n"; print MAIL " \n"; print MAIL "Ship To: \n"; print MAIL "-------- \n"; print MAIL " $s_first $s_last \n"; print MAIL " $s_addr \n"; print MAIL " $s_addr2 \n"; print MAIL " $s_city, $s_state $s_zip \n"; print MAIL " $s_phone \n"; print MAIL " \n"; print MAIL " \n"; print MAIL "Qty Price(\$) Product ID - Product Name\n"; print MAIL "===================================================================== \n"; print MAIL "$QUANTITY_1 \$$PRICE_1 $ID_1 - $NAME_1 $ADDTLINFO_1 \n"; if( $NAME_2 ) {print MAIL "$QUANTITY_2 \$$PRICE_2 $ID_2 - $NAME_2 $ADDTLINFO_2 \n";} if( $NAME_3 ) {print MAIL "$QUANTITY_3 \$$PRICE_3 $ID_3 - $NAME_3 $ADDTLINFO_3 \n";} if( $NAME_4 ) {print MAIL "$QUANTITY_4 \$$PRICE_4 $ID_4 - $NAME_4 $ADDTLINFO_4 \n";} if( $NAME_5 ) {print MAIL "$QUANTITY_5 \$$PRICE_5 $ID_5 - $NAME_5 $ADDTLINFO_5 \n";} if( $NAME_6 ) {print MAIL "$QUANTITY_6 \$$PRICE_6 $ID_6 - $NAME_6 $ADDTLINFO_6 \n";} if( $NAME_7 ) {print MAIL "$QUANTITY_7 \$$PRICE_7 $ID_7 - $NAME_7 $ADDTLINFO_7 \n";} if( $NAME_8 ) {print MAIL "$QUANTITY_8 \$$PRICE_8 $ID_8 - $NAME_8 $ADDTLINFO_8 \n";} if( $NAME_9 ) {print MAIL "$QUANTITY_9 \$$PRICE_9 $ID_9 - $NAME_9 $ADDTLINFO_9 \n";} if( $NAME_10 ){print MAIL "$QUANTITY_10 \$$PRICE_10 $ID_10 - $NAME_10 $ADDTLINFO_10 \n";} if( $NAME_11 ){print MAIL "$QUANTITY_11 \$$PRICE_11 $ID_11 - $NAME_11 $ADDTLINFO_11 \n";} if( $NAME_12 ){print MAIL "$QUANTITY_12 \$$PRICE_12 $ID_12 - $NAME_12 $ADDTLINFO_12 \n";} if( $NAME_13 ){print MAIL "$QUANTITY_13 \$$PRICE_13 $ID_13 - $NAME_13 $ADDTLINFO_13 \n";} print MAIL "===================================================================== \n"; print MAIL "SUBTOTAL: $SUBTOTAL \n"; print MAIL "TOTAL: $TOTAL \n"; print MAIL "\n"; print MAIL "FREIGHT: $SHIPPING \n"; print MAIL "\n\n"; print MAIL "Comments: \n"; print MAIL "--------- \n"; print MAIL "$comment \n"; print MAIL " \n"; close MAIL; } if( $mode eq "BOTH" || $mode eq "FILE") { $csvcomments = $comment; #$csvcomments =~ s/\"/$csvquote/ig; open (CSVF,">>$csvfilename"); print CSVF "\""; print CSVF "$months[$month] $day, $year $hour:$min:$sec"; print CSVF "\",\""; print CSVF "$b_first"; print CSVF "\",\""; print CSVF "$b_last"; print CSVF "\",\""; print CSVF "$b_addr"; print CSVF "\",\""; print CSVF "$b_addr2"; print CSVF "\",\""; print CSVF "$b_city"; print CSVF "\",\""; print CSVF "$b_state"; print CSVF "\",\""; print CSVF "$b_zip"; print CSVF "\",\""; print CSVF "$b_phone"; print CSVF "\",\""; print CSVF "$b_fax"; print CSVF "\",\""; print CSVF "$b_email"; print CSVF "\",\""; print CSVF "$s_first"; print CSVF "\",\""; print CSVF "$s_last"; print CSVF "\",\""; print CSVF "$s_addr"; print CSVF "\",\""; print CSVF "$s_addr2"; print CSVF "\",\""; print CSVF "$s_city"; print CSVF "\",\""; print CSVF "$s_state"; print CSVF "\",\""; print CSVF "$s_zip"; print CSVF "\",\""; print CSVF "$s_phone"; print CSVF "\",\""; print CSVF "$QUANTITY_1"; print CSVF "\",\""; print CSVF "\$$PRICE_1"; print CSVF "\",\""; print CSVF "$ID_1"; print CSVF "\",\""; print CSVF "$NAME_1"; print CSVF "\",\""; print CSVF "$ADDTLINFO_1"; print CSVF "\",\""; } # Send email conformation to the customer..... open (MAIL,"|$mailprogram"); print MAIL "To: $b_email\n"; print MAIL "From: $youremail\n"; print MAIL "Subject: Order Confirmation\n"; print MAIL "\n\n"; print MAIL "A new order has been received. A summary of this order appears below.\n"; print MAIL "\n"; print MAIL "Order Date: $months[$month] $day, $year $hour:$min:$sec \n"; print MAIL " \n"; print MAIL "Bill To: \n"; print MAIL "-------- \n"; print MAIL " $b_first $b_last \n"; print MAIL " $b_addr \n"; print MAIL " $b_addr2 \n"; print MAIL " $b_city, $b_state $b_zip \n"; print MAIL " $b_phone \n"; print MAIL " $b_fax \n"; print MAIL " $b_email \n"; print MAIL " \n"; print MAIL " \n"; print MAIL "Ship To: \n"; print MAIL "-------- \n"; if ( $s_addr eq "" ) { print MAIL " Use Billing Address\n"; } else { print MAIL " $s_first $s_last \n"; print MAIL " $s_addr \n"; print MAIL " $s_addr2 \n"; print MAIL " $s_city, $s_state $s_zip \n"; print MAIL " $s_phone \n"; } print MAIL " \n"; print MAIL " \n"; print MAIL "Qty Price(\$) Product ID - Product Name\n"; print MAIL "===================================================================== \n"; print MAIL "$QUANTITY_1 \$$PRICE_1 $ID_1 - $NAME_1 $ADDTLINFO_1 \n"; if( $NAME_2 ) {print MAIL "$QUANTITY_2 \$$PRICE_2 $ID_2 - $NAME_2 $ADDTLINFO_2 \n";} if( $NAME_3 ) {print MAIL "$QUANTITY_3 \$$PRICE_3 $ID_3 - $NAME_3 $ADDTLINFO_3 \n";} if( $NAME_4 ) {print MAIL "$QUANTITY_4 \$$PRICE_4 $ID_4 - $NAME_4 $ADDTLINFO_4 \n";} if( $NAME_5 ) {print MAIL "$QUANTITY_5 \$$PRICE_5 $ID_5 - $NAME_5 $ADDTLINFO_5 \n";} if( $NAME_6 ) {print MAIL "$QUANTITY_6 \$$PRICE_6 $ID_6 - $NAME_6 $ADDTLINFO_6 \n";} if( $NAME_7 ) {print MAIL "$QUANTITY_7 \$$PRICE_7 $ID_7 - $NAME_7 $ADDTLINFO_7 \n";} if( $NAME_8 ) {print MAIL "$QUANTITY_8 \$$PRICE_8 $ID_8 - $NAME_8 $ADDTLINFO_8 \n";} if( $NAME_9 ) {print MAIL "$QUANTITY_9 \$$PRICE_9 $ID_9 - $NAME_9 $ADDTLINFO_9 \n";} if( $NAME_10 ){print MAIL "$QUANTITY_10 \$$PRICE_10 $ID_10 - $NAME_10 $ADDTLINFO_10 \n";} if( $NAME_11 ){print MAIL "$QUANTITY_11 \$$PRICE_11 $ID_11 - $NAME_11 $ADDTLINFO_11 \n";} if( $NAME_12 ){print MAIL "$QUANTITY_12 \$$PRICE_12 $ID_12 - $NAME_12 $ADDTLINFO_12 \n";} if( $NAME_13 ){print MAIL "$QUANTITY_13 \$$PRICE_13 $ID_13 - $NAME_13 $ADDTLINFO_13 \n";} print MAIL "===================================================================== \n"; print MAIL "SUBTOTAL: $SUBTOTAL \n"; print MAIL "TOTAL: $TOTAL \n"; print MAIL "\n"; print MAIL "FREIGHT: $SHIPPING \n"; print MAIL "\n\n"; print MAIL "Comments: \n"; print MAIL "--------- \n"; print MAIL "$comment \n"; print MAIL " \n"; close MAIL; print "Content-type: text/html\n\n"; open (HEAD, $header); @LINES = <HEAD>; close HEAD; print @LINES; print "<h2>Thank you</h2>"; print "Thank you for your order from our online store. You will receive a confirmation email of your order "; print "momentarily. Please contact us at $youremail if you have any questions or concerns."; print "<P>"; print "<A HREF=\"$returnpage\" target=_top>Return Home</A>"; print "<P>"; open (FOOT, $footer); @LINES = <FOOT>; close FOOT; print @LINES; exit; or in the checkout.html file.. Code: <HTML> <HEAD> <TITLE> CHECKOUT -- Title Here </TITLE> <STYLE> .greetext { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;color: #006600;} .blacktext { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;color: #000000;} .checkout {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #000000;} .checkoutinput {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #000000;} .nopcart {background: #464444;border: 1px;font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #ffffff;} .nopheader {background: #464444;font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #FFFFFF;} .nopentry {background: #FFFFFF;font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #000000;} .noptotal {background: #FFFFFF;font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #000000;} .nopbutton {background: #FFFFFF;font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #000000;} </STYLE> <SCRIPT SRC="http://www.mydomain.com/language-en.js"></SCRIPT> <SCRIPT SRC="http://www.mydomain.com/nopcart.js"> </SCRIPT> <SCRIPT> function CheckForm( theform ) { var bMissingFields = false; var strFields = ""; if( theform.b_first.value == '' ){ bMissingFields = true; strFields += " Billing: First Name\n"; } if( theform.b_last.value == '' ){ bMissingFields = true; strFields += " Billing: Last Name\n"; } if( theform.b_addr.value == '' ){ bMissingFields = true; strFields += " Billing: Address\n"; } if( theform.b_city.value == '' ){ bMissingFields = true; strFields += " Billing: City\n"; } if( theform.b_state.value == '' ){ bMissingFields = true; strFields += " Billing: State\n"; } if( theform.b_zip.value == '' ){ bMissingFields = true; strFields += " Billing: Zipcode\n"; } if( theform.b_phone.value == '' ){ bMissingFields = true; strFields += " Billing: Phone\n"; } if( theform.b_email.value == '' ){ bMissingFields = true; strFields += " Billing: Email\n"; } if( bMissingFields ) { alert( "I'm sorry, but you must provide the following field(s) before continuing:\n" + strFields ); return false; } return true; } </SCRIPT> </head> </HEAD> <BODY BGCOLOR="White" TEXT="Black"> <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%> <TD VALIGN=TOP BGCOLOR=#663333> <IMG SRC="/images/one.gif" WIDTH=2 HEIGHT=20 ALT=""> <IMG SRC="/images/text.gif" WIDTH=391 HEIGHT=20 ALT="The Ultimate Delicacy"> </TD> </TR> </TABLE> <blockquote> <NOSCRIPT> Whoops, we detected that your browser does not have JavaScript, or it is disabled. Our product catalog requires that you have JavaScript enabled to order products. <a href="http://www.netscape.com">Netscape</a> and <a href="http://www.microsoft.com/ie">Microsoft</a> offer free browsers which support JavaScript. If you are using a JavaScript compliant browser and still have problems, make sure you have JavaScript enabled in your browser's preferences. </NOSCRIPT> <FONT CLASS="checkout"> <form action="cgi-bin/checkout.pl" method="POST" onSubmit="return CheckForm(this)"> <NOBR> <SCRIPT> CheckoutCart(); </SCRIPT> </NOBR> <br> <P> <font class="blacktext"> <b>Please fill out the following information below to complete your order.</b> </font> <p> <b><font class="greetext">Billing Information:</font></b><P> <TABLE class="blacktext"> <TR><TD>Name: </TD><TD><input type="text" size="18" name="b_first"> <input type="text" size="15" name="b_last"></TD></TR> <TR><TD>Address: </TD><TD><input type="text" size="37" name="b_addr"> </TD></TR> <TR><TD>Address: </TD><TD><input type="text" size="37" name="b_addr2"></TD></TR> <TR><TD>City: </TD><TD><input type="text" size="21" name="b_city"> </TD></TR> <TR><TD>State: </TD><TD><input type="text" size="1" name="b_state"> </TD></TR> <TR><TD>Zip: </TD><TD><input type="text" size="5" name="b_zip"></TD></TR> <TR><TD>Phone: </TD><TD><input type="text" size="37" name="b_phone"></TD></TR> <TR><TD>Fax: </TD><TD><input type="text" size="37" name="b_fax"></TD></TR> <TR><TD>Email: </TD><TD><input type="text" size="37" name="b_email"> </TD></TR> </TABLE> <p> <b><font class="greetext">Shipping Information (if different than billing):</font></b><P> <TABLE class="blacktext"> <TR><TD>Name: </TD><TD><input type="text" size="18" name="s_first"> <input type="text" size="15" name="s_last"></TD></TR> <TR><TD>Address: </TD><TD><input type="text" size="37" name="s_addr"> </TD></TR> <TR><TD>Address: </TD><TD><input type="text" size="37" name="s_addr2"></TD></TR> <TR><TD>City: </TD><TD><input type="text" size="21" name="s_city"> </TD></TR> <TR><TD>State: </TD><TD><input type="text" size="1" name="s_state"> </TD></TR> <TR><TD>Zip: </TD><TD><input type="text" size="5" name="s_zip"></TD></TR> <TR><TD>Phone: </TD><TD><input type="text" size="37" name="s_phone"></TD></TR> <TR><TD>Fax: </TD><TD><input type="text" size="37" name="s_fax"></TD></TR> <TR><TD>Email: </TD><TD><input type="text" size="37" name="s_email"> </TD></TR> </TABLE> <p> <FONT class="blacktext"> <b><font class="greetext">Comments/Special Instructions:</font></b><P> <TEXTAREA NAME="comment" ROWS=6 COLS=40> </TEXTAREA> </font> <input type=submit Value="Submit Order"> <INPUT type=RESET value=" Clear Form "> </p> </center> </FORM> </blockquote> </body> </html> Hi, PanM here. Trying to build a website to help my cousin sell his beautiful art. I am using a free web page at weebly.com and they have an option to use either PayPal or Google Checkout to put in shipping costs and go to the cart checkout. However, haven't evaluated Google yet, but PayPal does not do what I want. You have to put in various shipping prices and then it doesn't relate to the state or country unless you select all states, or anyway that's how I see it. I have found one on the net that wants $5 per month, but I am trying to do this for free. UPS, FedEx, and USPS have API's that can probably work, but I would prefer a HTML file or Javascript file in the page on my site. Can anyone help with this problem? Please. Thanks, PanM On my site's shopping cart, when clicking the "buy" button, it merely animates a little item that shows that something is now in the customer's cart. I'd like it to do this, and then redirect to "/cart", cutting down the work of what the user actually has to do (we only have one product). Here's what I'm working with: <!-- START ADD TO CART --> {% if featuredproduct.available %} <span class="featured-product price"><span>{{ featuredproduct.price | money }}</span>{% if featuredproduct.compare_at_price_max > featuredproduct.price %} <del>{{ featuredproduct.compare_at_price | money }}</del>{% endif %}</span> <input type="submit" value="{{ settings.text_addtocart }}" class=" add-to-cart addtocart button primary"> {% else %} <h3 class="featured-product price sold-out"><span>Sold Out</span></h3> <input type="submit" value="{{ settings.text_addtocart }}" class="featured-product add-to-cart button primary disabled" disabled="disabled "> {% endif %} <!-- END ADD TO CART --> Adding an "onclick="location.href='/cart';" after the input classes does not fire the actual act of adding the item to the cart, so it shows an empty cart on the redirect. JS newbie, sorry for the rough explanation. Any help greatly appreciated! Hi, Im using the old nopcard scripts on my site. It does every thing right except it does not send a Email to my to my email adres. I dont know how to correct this because i dont know Javascript. I include the script if anybody know how to alter it so that it will send the info to my email adres as well. Thank you very much for your previous help. Kees Meyer Oudtshoorn South Africa. The checkout.pl script : #!/usr/bin/perl #=====================================================================|| # NOP Design JavaScript Shopping Cart || # PERL CGI Checkout Module || # || # For more information on SmartSystems, or how NOPDesign can help you || # Please visit us on the WWW at http://www.nopdesign.com || # || # Javascript portions of this shopping cart software are available as || # freeware from NOP Design. You must keep this comment unchanged in || # your code. For more information contact FreeCart@NopDesign.com. || # || # JavaScript Shop Module, V.4.4.0 || #=====================================================================|| # || # Function: Writes available form elements from the NOP || # Free Cart (http://www.nopdesign.com/freecart) || # and other form elements to an email file, and || # send user confirmation || # || #=====================================================================|| require 5.001; ######################################################################## # # # User defined variables: # # $header - string value containing the complete # # path of the HTML page header # # $footer - string value containing the complete # # path of the HTML page footer # # $mailprogram - string value containing the complete path to # # the sendmail binary on the system. # # $youremail - string value containing the email address to # # send catalog orders in EMAIL or BOTH modes # # **Don't forget to put a \ before the @ in your # # email address. ie. spam\@nopdesign.com*** # # $returnpage - URL to send user when checkout is complete # # $csvfilename - string value containing the complete # # path of the user database. # # $csvquote - string value containing what to use for quotes # # in the csv file (typically "" or \") # # $mode - string value containing 'EMAIL', 'FILE' or # # 'BOTH' to determine if the script should send # # an email to you with the new order, write the # # order to a CSV file, or do both. # ######################################################################## $header = "header.html"; $footer = "footer.html"; $mailprogram = "/usr/lib/sendmail -t"; $returnpage = "/"; $youremail = "support\@ebookstore.co.za"; $csvfilename = "orders.csv"; $csvquote = "\"\""; $mode = "BOTH"; #These are required fields. I recommend enforcing these by javascript, #but let's just make sure here as well. @required = ( 'b_first', 'b_last', 'b_addr', 'b_city', 'b_state', 'b_zip', 'b_phone', 'b_email' ); ############################################################## #FUNCTION: urlDecode # #RETURNS: The decoded string. # #PARAMETERS: An encoded string. # #PURPOSE: Decodes a URL encoded string. # ############################################################## sub urlDecode { my ($string) = @_; $string =~ tr/+/ /; $string =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex($1))/eg; $string =~ s/['"]/\'/g; return ($string); } ############################################################## #FUNCTION: processCGI # #RETURNS: # #PARAMETERS: # #PURPOSE: Retrieves form data submitted via the 'GET' # # method and decodes it. You may then access # # the passed in variables via calls to $[name] # # where [name] is the name of the form element. # ############################################################## sub processCGI { local ($cgiData, $key, $value, $pair, @pairs); if ($ENV{'REQUEST_METHOD'} eq 'GET') { $cgiData = $ENV{'QUERY_STRING'}; } else { $cgiData = <STDIN>; } @pairs = split (/&/, $cgiData); foreach $pair (@pairs) { ($key, $value) = split (/\=/, $pair); $key = &urlDecode($key); $value = &urlDecode($value); if(defined ${$key}){ ${$key} .= ", ".$value; }else{ ${$key} = $value; } } } ############################################################## #FUNCTION: doFormError # #RETURNS: # #PARAMETERS: A error message string. # #PURPOSE: Generates an HTML page indicating a form # # submission error occurred. # ############################################################## sub doFormError { my ($errString) = @_; open (HEAD, $header); @LINES = <HEAD>; close HEAD; print "Content-type: text/html\n\n"; print @LINES; print "<FONT SIZE=+2>The form you submitted was not complete.<BR><BR></FONT>"; print "$errString<BR><BR>\n"; print "<INPUT TYPE=BUTTON ONCLICK='history.back()' VALUE=' Return to the checkout page '><HR>"; open (FOOT, $footer); @LINES = <FOOT>; close FOOT; print @LINES; exit; } ############################################################## #FUNCTION: doError # #RETURNS: # #PARAMETERS: A error message string. # #PURPOSE: Generates an HTML page indicating an error # # occurred. # ############################################################## sub doError { my ($errString) = @_; print "Content-type: text/html\n\n"; open (HEAD, $header); @LINES = <HEAD>; close HEAD; print @LINES; print "$errString<BR><BR>\n"; open (FOOT, $footer); @LINES = <FOOT>; close FOOT; print @LINES; exit; } ############################################################## #FUNCTION: invalidE # #RETURNS: 1 if invalid, 0 if valid. # #PARAMETERS: An email address variable. # #PURPOSE: Checks to see if a submitted email address is # # of the valid form 'x@y'. # ############################################################## sub invalidE { my ($szEmail) = @_; my ($user, $host); $szEmail =~ tr/A-Z/a-z/; if ($szEmail =~ /\s/) { return 1; } ($user, $host) = split (/\@/, $szEmail); if ($host =~ /compuserve/i) { ; } else { if (! $user =~ /\D/) { return 1; } if (! $host =~ /\D/) { return 1; } if (substr ($user,0,1) !~ /[a-z]/) { return 1; } } if ($szEmail =~ /\w+\@[\w|\.]/) { return 0; } else { return 1; } } sub populateDateVar { (Taken out because Text to long for email) "===================================================================== \n"; print MAIL "$QUANTITY_1 \R$PRICE_1 $ID_1 - $NAME_1 $ADDTLINFO_1 \n"; if( $NAME_2 ) {print MAIL "$QUANTITY_2 \R$PRICE_2 $ID_2 - $NAME_2 $ADDTLINFO_2 \n";} if( $NAME_3 ) {print MAIL "$QUANTITY_3 \R$PRICE_3 $ID_3 - $NAME_3 $ADDTLINFO_3 \n";} if( $NAME_4 ) {print MAIL "$QUANTITY_4 \R$PRICE_4 $ID_4 - $NAME_4 $ADDTLINFO_4 \n";} if( $NAME_5 ) {print MAIL "$QUANTITY_5 \R$PRICE_5 $ID_5 - $NAME_5 $ADDTLINFO_5 \n";} if( $NAME_6 ) {print MAIL "$QUANTITY_6 \R$PRICE_6 $ID_6 - $NAME_6 $ADDTLINFO_6 \n";} if( $NAME_7 ) {print MAIL "$QUANTITY_7 \R$PRICE_7 $ID_7 - $NAME_7 $ADDTLINFO_7 \n";} if( $NAME_8 ) {print MAIL "$QUANTITY_8 \R$PRICE_8 $ID_8 - $NAME_8 $ADDTLINFO_8 \n";} if( $NAME_9 ) {print MAIL "$QUANTITY_9 \R$PRICE_9 $ID_9 - $NAME_9 $ADDTLINFO_9 \n";} if( $NAME_10 ){print MAIL "$QUANTITY_10 \R$PRICE_10 $ID_10 - $NAME_10 $ADDTLINFO_10 \n";} if( $NAME_11 ){print MAIL "$QUANTITY_11 \R$PRICE_11 $ID_11 - $NAME_11 $ADDTLINFO_11 \n";} if( $NAME_12 ){print MAIL "$QUANTITY_12 \R$PRICE_12 $ID_12 - $NAME_12 $ADDTLINFO_12 \n";} if( $NAME_13 ){print MAIL "$QUANTITY_13 \R$PRICE_13 $ID_13 - $NAME_13 $ADDTLINFO_13 \n";} print MAIL "===================================================================== \n"; print MAIL "SUBTOTAL: $SUBTOTAL \n"; print MAIL "TOTAL: $TOTAL \n"; print MAIL "\n"; print MAIL "\n\n"; print MAIL "Comments: \n"; print MAIL "--------- \n"; print MAIL "$comment \n"; print MAIL " \n"; close MAIL; } if( $mode eq "BOTH" || $mode eq "FILE") { $csvcomments = $comment; #$csvcomments =~ s/\"/$csvquote/ig; open (CSVF,">>$csvfilename"); print CSVF "\""; print CSVF "$months[$month] $day, $year $hour:$min:$sec"; print CSVF "\",\""; print CSVF "$b_first"; print CSVF "\",\""; print CSVF "$b_last"; print CSVF "\",\""; print CSVF "$b_addr"; print CSVF "\",\""; print CSVF "$b_addr2"; print CSVF "\",\""; print CSVF "$b_city"; print CSVF "\",\""; print CSVF "$b_state"; print CSVF "\",\""; print CSVF "$b_zip"; print CSVF "\",\""; print CSVF "$b_phone"; print CSVF "\",\""; print CSVF "$b_fax"; print CSVF "\",\""; print CSVF "$b_email"; print CSVF "\",\""; print CSVF "$s_first"; print CSVF "\",\""; print CSVF "$s_last"; print CSVF "\",\""; print CSVF "$s_addr"; print CSVF "\",\""; print CSVF "$s_addr2"; print CSVF "\",\""; print CSVF "$s_city"; print CSVF "\",\""; print CSVF "$s_state"; print CSVF "\",\""; print CSVF "$s_zip"; print CSVF "\",\""; print CSVF "$s_phone"; print CSVF "\",\""; print CSVF "$QUANTITY_1"; print CSVF "\",\""; print CSVF "\R$PRICE_1"; print CSVF "\",\""; print CSVF "$ID_1"; print CSVF "\",\""; print CSVF "$NAME_1"; print CSVF "\",\""; print CSVF "$ADDTLINFO_1"; print CSVF "\",\""; print CSVF "$QUANTITY_2"; print CSVF "\",\""; print CSVF "\R$PRICE_2"; print CSVF "\",\""; print CSVF "$ID_2"; print CSVF "\",\""; print CSVF "$NAME_2"; print CSVF "\",\""; print CSVF "$ADDTLINFO_2"; print CSVF "\",\""; print CSVF "$QUANTITY_3"; print CSVF "\",\""; print CSVF "\R$PRICE_3"; print CSVF "\",\""; print CSVF "$ID_3"; print CSVF "\",\""; print CSVF "$NAME_3"; print CSVF "\",\""; print CSVF "$ADDTLINFO_3"; print CSVF "\",\""; print CSVF "$QUANTITY_4"; print CSVF "\",\""; print CSVF "\R$PRICE_4"; print CSVF "\",\""; print CSVF "$ID_4"; print CSVF "\",\""; print CSVF "$NAME_4"; print CSVF "\",\""; print CSVF "$ADDTLINFO_4"; print CSVF "\",\""; print CSVF "$QUANTITY_5"; print CSVF "\",\""; print CSVF "\R$PRICE_5"; print CSVF "\",\""; print CSVF "$ID_5"; print CSVF "\",\""; print CSVF "$NAME_5"; print CSVF "\",\""; print CSVF "$ADDTLINFO_5"; print CSVF "\",\""; print CSVF "$QUANTITY_6"; print CSVF "\",\""; print CSVF "\R$PRICE_6"; print CSVF "\",\""; print CSVF "$ID_6"; print CSVF "\",\""; print CSVF "$NAME_6"; print CSVF "\",\""; print CSVF "$ADDTLINFO_6"; print CSVF "\",\""; print CSVF "$QUANTITY_7"; print CSVF "\",\""; print CSVF "\R$PRICE_7"; print CSVF "\",\""; print CSVF "$ID_7"; print CSVF "\",\""; print CSVF "$NAME_7"; print CSVF "\",\""; print CSVF "$ADDTLINFO_7"; print CSVF "\",\""; print CSVF "$QUANTITY_8"; print CSVF "\",\""; print CSVF "\R$PRICE_8"; print CSVF "\",\""; print CSVF "$ID_8"; print CSVF "\",\""; print CSVF "$NAME_8"; print CSVF "\",\""; print CSVF "$ADDTLINFO_8"; print CSVF "\",\""; print CSVF "$QUANTITY_9"; print CSVF "\",\""; print CSVF "\R$PRICE_9"; print CSVF "\",\""; print CSVF "$ID_9"; print CSVF "\",\""; print CSVF "$NAME_9"; print CSVF "\",\""; print CSVF "$ADDTLINFO_9"; print CSVF "\",\""; print CSVF "$QUANTITY_10"; print CSVF "\",\""; print CSVF "\R$PRICE_10"; print CSVF "\",\""; print CSVF "$ID_10"; print CSVF "\",\""; print CSVF "$NAME_10"; print CSVF "\",\""; print CSVF "$ADDTLINFO_10"; print CSVF "\",\""; print CSVF "$QUANTITY_11"; print CSVF "\",\""; print CSVF "\R$PRICE_11"; print CSVF "\",\""; print CSVF "$ID_11"; print CSVF "\",\""; print CSVF "$NAME_11"; print CSVF "\",\""; print CSVF "$ADDTLINFO_11"; print CSVF "\",\""; print CSVF "$QUANTITY_12"; print CSVF "\",\""; print CSVF "\R$PRICE_12"; print CSVF "\",\""; print CSVF "$ID_12"; print CSVF "\",\""; print CSVF "$NAME_12"; print CSVF "\",\""; print CSVF "$ADDTLINFO_12"; print CSVF "\",\""; print CSVF "$QUANTITY_13"; print CSVF "\",\""; print CSVF "\R$PRICE_13"; print CSVF "\",\""; print CSVF "$ID_13"; print CSVF "\",\""; print CSVF "$NAME_13"; print CSVF "\",\""; print CSVF "$ADDTLINFO_13"; print CSVF "\",\""; print CSVF "$SUBTOTAL"; print CSVF "\",\""; print CSVF "$TOTAL"; print CSVF "\",\""; print CSVF "$SHIPPING"; print CSVF "\",\""; print CSVF "$comment"; print CSVF "\"\n"; close CSVF; } # Send email conformation to the customer..... open (MAIL,"|$mailprogram"); print MAIL "To: $b_email\n"; print MAIL "From: $youremail\n"; print MAIL "Subject: Order Confirmation\n"; print MAIL "\n\n"; print MAIL "A new order has been received. A summary of this order appears below.\n"; print MAIL "\n"; print MAIL "Order Date: $months[$month] $day, $year $hour:$min:$sec \n"; print MAIL " \n"; print MAIL "Bill To: \n"; print MAIL "-------- \n"; print MAIL " $b_first $b_last \n"; print MAIL " $b_addr \n"; print MAIL " $b_addr2 \n"; print MAIL " $b_city, $b_state $b_zip \n"; print MAIL " $b_phone \n"; print MAIL " $b_fax \n"; print MAIL " $b_email \n"; print MAIL " \n"; print MAIL " \n"; print MAIL "-------- \n"; if ( $s_addr eq "" ) { print MAIL " Use Billing Address\n"; } else { print MAIL " $s_first $s_last \n"; print MAIL " $s_addr \n"; print MAIL " $s_addr2 \n"; print MAIL " $s_city, $s_state $s_zip \n"; print MAIL " $s_phone \n"; } print MAIL " \n"; print MAIL " \n"; print MAIL "Qty Price(\R) Product ID - Product Name\n"; print MAIL "===================================================================== \n"; print MAIL "$QUANTITY_1 \R$PRICE_1 $ID_1 - $NAME_1 $ADDTLINFO_1 \n"; if( $NAME_2 ) {print MAIL "$QUANTITY_2 \R$PRICE_2 $ID_2 - $NAME_2 $ADDTLINFO_2 \n";} if( $NAME_3 ) {print MAIL "$QUANTITY_3 \R$PRICE_3 $ID_3 - $NAME_3 $ADDTLINFO_3 \n";} if( $NAME_4 ) {print MAIL "$QUANTITY_4 \R$PRICE_4 $ID_4 - $NAME_4 $ADDTLINFO_4 \n";} if( $NAME_5 ) {print MAIL "$QUANTITY_5 \R$PRICE_5 $ID_5 - $NAME_5 $ADDTLINFO_5 \n";} if( $NAME_6 ) {print MAIL "$QUANTITY_6 \R$PRICE_6 $ID_6 - $NAME_6 $ADDTLINFO_6 \n";} if( $NAME_7 ) {print MAIL "$QUANTITY_7 \R$PRICE_7 $ID_7 - $NAME_7 $ADDTLINFO_7 \n";} if( $NAME_8 ) {print MAIL "$QUANTITY_8 \R$PRICE_8 $ID_8 - $NAME_8 $ADDTLINFO_8 \n";} if( $NAME_9 ) {print MAIL "$QUANTITY_9 \R$PRICE_9 $ID_9 - $NAME_9 $ADDTLINFO_9 \n";} if( $NAME_10 ){print MAIL "$QUANTITY_10 \R$PRICE_10 $ID_10 - $NAME_10 $ADDTLINFO_10 \n";} if( $NAME_11 ){print MAIL "$QUANTITY_11 \R$PRICE_11 $ID_11 - $NAME_11 $ADDTLINFO_11 \n";} if( $NAME_12 ){print MAIL "$QUANTITY_12 \R$PRICE_12 $ID_12 - $NAME_12 $ADDTLINFO_12 \n";} if( $NAME_13 ){print MAIL "$QUANTITY_13 \R$PRICE_13 $ID_13 - $NAME_13 $ADDTLINFO_13 \n";} print MAIL "===================================================================== \n"; print MAIL "SUBTOTAL: $SUBTOTAL \n"; print MAIL "TOTAL: $TOTAL \n"; print MAIL "\n"; print MAIL "\n\n"; print MAIL "Comments: \n"; print MAIL "--------- \n"; print MAIL "$comment \n"; print MAIL " \n"; close MAIL; print "Content-type: text/html\n\n"; open (HEAD, $header); @LINES = <HEAD>; close HEAD; print @LINES; print "<h2>Thank you</h2>"; print "Thank you for your order."; print "Please contact us at $youremail if you have any problems questions or concerns. Thank U again for your support Kees Meyer."; print "<P>"; print "<A HREF=\"$returnpage\" rel="nofollow" target=_top>Return Home</A>"; print "<P>"; open (FOOT, $footer); @LINES = <FOOT>; close FOOT; print @LINES; exit; Hello! I am trying to find a script that allows you to open multiple browser tabs and then close each of those tabs, either one by one or all at once. Does anyone know how to do this please? Thanks so much for your help. I want to have another go at Javascript. I have several books on the subject but I find that my eyesight is a major problem. Therefore I want to try an on-line solution, preferably free. I have Googled, but there are so many that I am almost dizzy with the choices. Perhaps someone could recommend one. Not too fussy visually. My knowledge is VERY basic. Frank Does anyone know how to make URL links that use Javascript still work when users have Javascript disabled on their browser? The only reason I'm using JS on a URL is because my link opens a PDF file, and I'm forcing it not to cache so users have the latest version. I tried the <script><noscript> tags, but I'm not sure if I'm using it correctly, as my URL completely disappears. Below is my HTML/Javascript code: <p class="download"> <script type="text/javascript">document.write("<span style=\"text-decoration: underline;\"><a href=\"javascript:void(0);\" onclick=\"window.open( 'http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf?nocache='+ Math.floor( Math.random()*11 ) );\" >The Child Magazines Media Kit</a></span> (PDF 1 MB) ");</script> <noscript><span style="text-decoration: underline;"><a href="http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf" >The Child Magazines Media Kit</a></span> (PDF 1 MB)</noscript> </p> Thanks for any help, Michael Hi, I have the following code snippet: test.html ====== <script language="javascript" type="text/javascript"> var testVariable = "test"; </script> <script language="javascript" type="text/javascript" src="test.js"> </script> test.js ===== var testVariable = window.top.testVariable; In firefox, I'm able to access testvariable defined within test.html in test.js. But in chrome, test.js couldnot get the window.top.testVariable field defined in test.html. Can any one please let me know how i can make it work in chrome?. Am i missing something here?. Hi Guys, I am new at JavaScript and start to do some tutorials.What I am trying to do here is prompting user to input a name and if the name was valid the page(document) will display with all objects like the button.But if user enter a wrong name then the button will be disabled! I create the following code but it did not work <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>New Web Project</title> <script language="JavaScript" type=""> function changeColor(){ document.bgColor = "Gray"; } </script> </head> <body> <script language="JavaScript" type="text/javascript"> var person = ""; person = prompt('What is Your Name:'); if (person == "Foo") { document.write("<h1 />Welcome " + person); document.bgColor = "Yellow"; } else { document.write("<h1 />Access Denied!!!!"); document.bgColor = "Red"; document.getElementById("gree").disabled = true; } </script> <div> <p/><input id="gree" type="button" value="Gray " onClick="changeColor();"> </div> </body> </html> as you can see I used the: document.getElementById("gree").disabled = true; but it did not work , could you please give an idea how I can solve this problem? Thanks Hey, I've got to make the values of some textboxes change the co-ordinates of my sprite on a canvas and havent a clue on how to do it, Here is my form with the two textboxes and submit button: <form> x: <input type="text" name="x" /><br /> y: <input type="text" name:"y" /><br /> <input type="submit" value="Submit"/><br /> </form> And i need it so that they change the values of these: //this shows where my sprite will start on the canvas var block_x; var block_y; searched the internet for hours and cant really find anything i understand or works. any help is much appreciated I want to insert this js snippet Code: function addText(smiley) { document.getElementById('message').value += " " + smiley + " "; document.getElementById('message').focus(); return false; } to a loaded iframe with name&id chtifrm. I can access it & change embed something in its html via using something like: Code: $(parent.chtifrm.document.body).append('<div id=\"smly\" style=\"cursor:pointer;float:left;top:200px;display:none;position:absolute;\"><\/div>'); .... Code: parent.chtifrm.document.getElementById('chatbox_option_disco').style.display == 'none' but how do I insert js in the head of loaded iframe? Hi Guys I am trying to modify the functionality of my page. I want to be able to activate this piece of code using another javascript function. This is the code I want to activate: Code: <script type="text/javascript"><!-- $('#button-cart').bind('click', function() { $.ajax({ url: 'index.php?route=checkout/cart/update', type: 'post', data: $('.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea, .date_data input[type=\'text\']'), dataType: 'json', success: function(json) { $('.success, .warning, .attention, information, .error').remove(); if (json['error']) { if (json['error']['warning']) { $('#notification').html('<div class="warning" style="display: none;">' + json['error']['warning'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>'); $('.warning').fadeIn('slow'); } for (i in json['error']) { $('#option-' + i).after('<span class="error">' + json['error'][i] + '</span>'); } } if (json['success']) { $('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>'); $('.success').fadeIn('slow'); $('#cart_total').html(json['total']); $('html, body').animate({ scrollTop: 0 }, 'slow'); } } }); }); //--></script> And this is how I want the format of the function to be: function testsession() { if there is a session called 'hiredate' { activate the script above } else { var el = document.getElementById("product_data"); } } I just dont know how to write this in javascript Could you help me if possible please I got an index.php Code: <html> <form action="bacakomik.php" method='post'> <select name="kodekomik"> <option value='../komik1/|23'>Judul Komik1</option> <option value="../komik2/|20">Judul Komik2</option> <option value="../komik3/|10">Juduk Komik3</option> <option value="../komik4/|20">Judul Komik4</option> </select> <input type="submit" /> </form> <?php echo ('<select>'); echo ('<option value= "'.$i.'">'.'Page '.$i.'</option>'); echo ('</select>'); ?> </html> As you can see, each of the option brings specific value "../komik1/|23" komik1 is a directory | is a delimiter 23 is the pages in one chapter and can be considered also as how many images are there on a specific directory This is my bacakomik.php Code: <?php $dirkomik = $_POST['kodekomik']; $exploded = explode("|", $dirkomik); echo ($exploded[0]); //picture directory echo ("<br>"); echo ($exploded[1]); //total page in the comic $pagecount = (int)$exploded[1]; //Take last posted value, process it right away echo ('<FORM name="guideform"> '); echo ('<select name="guidelinks">'); $i=1; do { echo ('<option value= "'.$i.'">'.'Page '.$i.'</option>'); $i= $i+1; }while($i <= $pagecount); //Printing option and select echo ("</select>"); ?> <input type="button" name="go" value="Go!" onClick="document.getElementById('im').src=document.guideform.guidelinks.options[document.guideform.guidelinks.selectedIndex].value+'.png';"> </FORM> <img src="img0.jpg" id="im"> With the current code on bacakomik.php, I only can change the img src of id "im" in the same directory only. What I want is that the Javascript could "add" the "$exploded[0]" variable so that the picture can be loaded from different directory. Anyone can do this? I believe that the fix should be somewhere on input tag inside OnClick, or do you know where? Anyway, I found this on the net http://p2p.wrox.com/php-faqs/11606-q...avascript.html Please help me to those who can... All -- I have a JavaScript config file called gameSetting.js which contains a bunch of variables which configures a particular game. I also have a shared JavaScript library which uses the variables in gameSetting.js, which I include like so: <script type="text/javascript" src="gameSetting.js" ></script> <script type="text/javascript" src="gameLibrary.js" ></script> In gameSetting.js I have: $(document).ready(function() { // call some functions / classes in gameLibrary.js } in Firefox, Safari, and Chrome, this works fine. However, in IE, when it's parsing gameSetting.js, it complains that the functions that live in gameLibrary.js aren't defined. When it gets to parsing gameLibrary.js, the variables in gameSetting.js are reported as not being defined. I've tried dynamically bootstrapping the gameLibrary file using this function in document.ready for dynamic load... $.getScript("gameLibrary.js"); However, the same problem still happens in IE, where when it parses the files individually it's not taking into context the file/variables that came before, so it's not an out of load order problem. My options a 1) collapsing all the functions in gameLibrary.js and variables in gameSetting.js into one file. However, this is not practical because this is dealing with literally hundreds of games, and having a gameLibrary.js in ONE location for ONE update is what makes most logical sense. 2) figure out a way to get this to work where variables in file1 are accessible to file2 in IE (as it seems they are in other browsers). jQuery seems to be able to have multiple plugins that all refer to the based jQuery-1.3.2.js, so I know there is a way to get this to work. Help appreciated. Nero I wrote a log function that took note of various function calls. Thinking that functions are first class objects, and objects have properties, I made the name of each logged function a property of that function, e.g., brightenInnerPara.name = "brightenInnerPara"; Every browser I tried (Firefox, MSIE, Opera, Chrome, Safari) accepted the assignment, no problem. In Firefox and MSIE, the result was what I wanted: brightenInnerPara.name == "brightenInnerPara" But in the others, the result was: brightenInnerPara.name == null Question 1. Which Javascript is correct here? I favor Firefox and MSIE, not merely because they were willing to give me what I wanted, but also because it makes no sense to accept an assignment statement without throwing an error and then give it a null semantics, like Chrome, Opera, and Safari did. I found a workaround, using assignments like this: brightenInnerPara.prototype.name = "brightenInnerPara"; To my surprise, that worked in every browser. But I don't know why. It seems that such assignments are enough to cause each function to have its own distinct prototype. Question 2. Just how inefficient is my workaround, and why does it work? HI All, I'm trying to create a web form that asks for username and password. What im using as validation is http codes. If users inputs correct credentials it will generate a 200 -ok if password is incorrect it will generate a 400 http error. My script is below which i admit is quite rough. but i wish to be pointed in the direction. I want to accomplish the following: If on form submit http is 200 redirect to specified URL. if http 400 i want to add a warning message "Invalid Password, try again" or something like that. ANy help, please. Thanks. --------------------------------------------------------------------- [code] function checkUrl(form1) { var username = form1.username.value; var password = form1.password.value; var url = "https://some url" ; var data = "<cwaRequests xmlns=http://schemas.microsoft.com/2006/09/rtc/cwa>...</cwaRequests>" ; var httpRequest = new XMLHttpRequest(); var isAsync = true; httpRequest.open("POST", url, isAsync); httpRequest.setRequestHeader("Accept", "*/*"); httpRequest.setRequestHeader("UserAgent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50215)"); httpRequest.setRequestHeader("ContentType", "application/x-www-form-urlencoded"); httpRequest.setRequestHeader("Timeout", 1000*60); httpRequest.setRequestHeader("CWA-Ticket", this.authTicket); httpRequest.onreadystatechange = ReadyStateChanged; httpRequest.send(data); function ReadyStateChanged() { if (httpRequest.readyState == 4) { if (httpRequest.Status == 200) { window.location = url var responseText = httpRequest.ResponseText; } else { alert (Password incorrect, Please try again; } } } } [code] What is so good about javascript? I don't think it is that good, so can someone please explain the pros and cons of JavaScript. 1st part i have a main jsp page with some values. For example 5 text boxes and one submit button. When i click on the submit button a popup form should generate with a list box. when i select a value from the listbox the value should be transferred to the main jsp(say in 5th textbox )and 2nd part along with these 5 values the control should transfer to another jsp. i am able to do the first part but second part is not getting. Thanks in advance. |