/    Sign up×
Community /Pin to ProfileBookmark

Javascript Order Form help.

can anyone explain why this script adds the variable tax ok but not the variable ttax? I have hilighted the code where ttax is located because thats the one that isnt adding correctly. thank you in advance.

<% Response.Buffer = 1 %>

<script language=”jscript” runat=server>
// since I’ve already written this code once in javascript (navigation.inc),
// and I don’t really want to do it again in VBscript,
// I’ll just specify javascript for this one chunk of server-side
// code. It makes the page load a *little* slower, but
// tough luck.

var liveClasses = 0;

function formatCurrency(num) {
num = num.toString().replace(/$|,/g,”);
if(isNaN(num)) num = “0”;
cents = Math.floor((num*100+0.500001)%100);
num = Math.floor(num).toString();
if(cents < 10) cents = “0” + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*
i+3))+’,’+num.substring(num.length-(4*i+3));
return (num + ‘.’ + cents);
}

function parseDate(vbdate) {
/* takes the native vb date from the database and uses a
*
built in jscript function to parse it and create a date
* object. Then outputs the date in a more appealing way.
*
/
var a, b, c;
var d = new Date();
d.setTime(Date.parse(vbdate))
a = (d.getMonth() + 1) + “”;
b = d.getDate() + “”;
c = d.getFullYear() + “”;

if (a.length == 1) a = “0” + a;
if (b.length == 1) b = “0” + b;

return a + ‘/’ + b + ‘/’ + c;

}

function getQty(eid, cart)
// get the qty of something in the cart, given the eid.
{
for (var x=0; x<cart.length; x++) {
if (cart[x][0] == eid) return cart[x][2];
}
return false;
}

var grandTotal = 0;
var totaltax = new Number(0);
var subtotal = 0;
var mailBody = “A registration request has been made for the following classes:nn”;
var eventLessThanFiveDaysAway = 0;
var strEventIDs=””;

function getCartContents()
{
var strHTML = “”;
var now = new Date();
var cart = new String();

// Basic shopping cart parsing functions: produces a 2 dimensional array with product data.
if ((Request.Cookies(“ascoltaCart”) + “”) != “”) {
cart = Request.Cookies(“ascoltaCart”) + “”;
}
else {
cart = Request.Querystring(“cart”) + “”;
}

cart = cart.split(“|”);
for (var x=0; x<cart.length; x++) cart[x] = cart[x].split(“:”);

var conn = Server.CreateObject(“ADODB.Connection”);
var rsCo = Server.CreateObject(“ADODB.Recordset”);

var strSQL = “SELECT distinct ClassType.ClassType as CourseShortName, “;
strSQL += “ClassType.ClassTypeName as CourseLongName, “;
strSQL += “ClassType.ClassTypeDuration, “;
strSQL += “ClassType.ClassTypeFee as CourseFee, “;
strSQL += “ClassType.Acronym AS Acronym, “;
strSQL += “Events.StartDate as EventStartDate, “;
strSQL += “Location.Location as EventLocation, “;
strSQL += “TaxRate.Rate as taxRate, “;
strSQL += “SelfStudy.UnitPrice as kitPrice, “;
[COLOR=”Red”]strSQL += “labor_tax.no_labortax as ltax, “;[/COLOR]
strSQL += “events.eventid as EventID “;
strSQL += “FROM ClassType INNER JOIN Events ON ClassType.ClassTypeID = Events.ClassTypeID “;
strSQL += “LEFT JOIN Resources ON ClassType.ClassTypeID = Resources.ClassTypeID “;
strSQL += “LEFT JOIN SelfStudy ON Resources.SelfStudyID = SelfStudy.SelfStudyID “;
strSQL += “INNER JOIN Location ON Events.LocationID = Location.LocationID “;
[COLOR=”red”]strSQL += “LEFT JOIN labor_tax ON location.locationid = labor_tax.locationid “;[/COLOR]
strSQL += “left JOIN TaxRate ON Location.LocationID = TaxRate.LocationID “;
strSQL += “WHERE events.eventid in (“;

for (var x=0; x<cart.length; x++) {
strSQL += cart[x][0] + “,”;
strEventIDs += cart[x][0] + “|”;
}
strSQL = strSQL.substring(0, strSQL.length – 1);
strEventIDs = strEventIDs.substring(0,strEventIDs.length -1);

strSQL += “)”;

conn.open(Session(“strConn”));
rsCo.open(strSQL, conn, 3, 1);

if (cart.length > 0) {
while (!rsCo.EOF)
{
var qty = getQty(rsCo(“EventID”) + “” – 0, cart);

if ((Request.Cookies(“ascoltaCart”) + “”) == “”) { qty = 1; }

var fee = rsCo(“CourseFee”) + “” – 0;
var kitPrice = 0;
var tax = 0;
[COLOR=”red”]var ltax = rsCo(“ltax”) + “” – 0;[/COLOR]
var total = 0;
var productid = new String(rsCo(“CourseShortName”));

// start San Jose Discount
if (rsCo(“EventLocation”) == “San Jose, CA”) {
fee=(rsCo(“CourseFee”)*.9) + “” – 0;
}
// end San jose Discount

if (productid.search(“LIV-“) != -1) {
liveClasses += 1;
}

if (rsCo(“kitprice”) + “” != “null”) {
kitPrice=rsCo(“kitprice”);

// start WA Tax
if (rsCo(“taxrate”)+””!=”null” && rsCo(“EventLocation”) == “Seattle (Bellevue), WA”)
{
tax = (rsCo(“taxRate”) * rsCo(“kitPrice”) * qty);
[COLOR=”red”]ttax = (fee * ltax * qty);[/COLOR]
}

// end WA Tax
else if (rsCo(“taxrate”)+””!=”null”){ tax = rsCo(“taxRate”) * rsCo(“kitPrice”) * qty;
[COLOR=”red”]ttax = (0 * qty);[/COLOR]
}
}

subtotal += (kitPrice + fee) * qty;
total = (kitPrice + fee + tax +[COLOR=”red”] ttax[/COLOR] ) * qty ;
grandTotal += total;
totaltax += tax;
tax = formatCurrency(tax);
total = formatCurrency(total);
fee = formatCurrency(fee);

strHTML += “<tr class=’bodyTextSmall’>”;
strHTML += “<td align=’left’>” + (rsCo(“CourseLongName”) + “”);
if (rsCo(“Acronym”) != ”) {
strHTML += “<br>(<b>” + rsCo(“Acronym”) + “</b>)”;
}
strHTML += “</td><td align=’center’><nobr>” + (rsCo(“EventLocation”) + “”) + ‘</nobr></td>’;
strHTML += “<td align=’center’><nobr>” + parseDate(rsCo(“EventStartDate”) + “”) + ‘</nobr></td>’;
strHTML += “<td align=’center’>” + qty + “</td>”;
strHTML += “<td align=’right’>$” + fee + ‘&nbsp;</td>’;
strHTML += “<td align=’right’>$” + kitPrice + ‘&nbsp;</td>’;
strHTML += “<td align=’right’>$” + total + ‘&nbsp;</td>’;
strHTML += “</tr>”;
strHTML += ‘<tr><td colspan=7 bgcolor=”#443399″ width=700><img src=”images/blank.gif” width=1 height=1></td></tr>’;

mailBody += “Class: ” + rsCo(“CourseShortName”) + “: ” + rsCo(“CourseLongName”) + “n”;
mailBody += “Location: ” + rsCo(“EventLocation”) + “n”;
mailBody += “Start Date: ” + parseDate(rsCo(“EventStartDate”)) + “n”;
mailBody += “Quantity: ” + qty + “n”;
mailBody += “Course Price: $” + fee + “n”;
mailBody += “Kit Price: $” + kitPrice + “n”;
mailBody += “Unit Tax: $” + tax + “n”;
mailBody += “Item Total: $” + total + “nn”;

if ( ((Date.parse(rsCo(“EventStartDate”)) – now.getTime()) / 1000 / 60 / 60 / 24) < 6)
eventLessThanFiveDaysAway = 1;

rsCo.moveNext();
}
}

Session(‘liveClasses’) = liveClasses;

grandTotal = formatCurrency(grandTotal);
rsCo.close();
conn.close();
var rsCo = null;
var conn = null;
return strHTML;

}
</script>

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @debriscreator spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...