I have the following javascript functions which i have been using on an asp website to calculate freight, and it has only ever allowed for shipping to one address.
Now customers can choose two ship 4 different items to 4 different addresses so I need to update this to calculate the freight to each location and then add it together, how can i do that.
this is what is being used now when a user enters a shipping postcode and tabs off the field, it calls onChange="getFreight(this.value)"
var freightareas = new Array()
<%
qry = "FreightList"
set rsqry = dbConn.execute(qry)
js_counter = 0
do until rsqry.eof
%>freightareas[<% =js_counter %>] = new freightarea(<% =rsqry("PostcodeStart") %>,<% =rsqry("PostcodeEnd") %>,<% =rsqry("FreightCost") %>)<%
response.write(chr(13) & chr(10))
rsqry.movenext
js_counter = js_counter + 1
loop
%>
freightareas.length = <% =js_counter %>
function freightarea(PostcodeStart,PostcodeEnd,FreightCost) {
this.PostcodeStart = PostcodeStart
this.PostcodeEnd = PostcodeEnd
this.FreightCost = FreightCost
}
function getFreight(postcode) {
for(i=0;i<freightareas.length;i++) {
if(freightareas[i].PostcodeStart <= postcode && freightareas[i].PostcodeEnd >= postcode) {
if (parseFloat(document.order.winepurchased_final.value) < 350) {
document.order.freightcost.value = freightareas[i].FreightCost * document.order.totalquantity.value
document.order.freightcost_final.value = freightareas[i].FreightCost * document.order.totalquantity.value
}
else {
document.order.freightcost.value = 0
document.order.freightcost_final.value = 0
document.order.freefreight.value = " Freight is free over $350";
}
}
}
calTotal()
}