dwong
11-22-2003, 06:51 PM
This is my script I have messed up the subtotal amount which I am not getting in the subtotal column
Q. The main question is , I want to add features like delete and/or change the qty of a selected item, how do I do that ?
------------------------------------------------------------------
<SCRIPT>
function deleteCookie (name, path, domain) {
if (getCookie(name)) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}
function getCookie(name) {
var prefix = name + "=";
var begin = document.cookie.indexOf(prefix);
if (begin == -1) return null;
var end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin + prefix.length, end));
}
function setCookie(name, value, expires, path, domain, secure) {
document.cookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
var purse = getCookie("purse");
if (!purse) purse = 0;
var shoes = getCookie("shoes");
if (!shoes) shoes = 0;
var sandals = getCookie("sandals");
if (!sandals) sandals = 0;
var wallet = getCookie("wallet");
if (!wallet) wallet = 0;
var total = 20 * purse + 25 * shoes + 15 * sandals + 10 * wallet;
function getValues() {
with (document.submitForm) {
purse.value = purse;
shoes.value = shoes;
sandals.value = sandals;
wallet.value = wallet;
total.value = total;
}
}
</SCRIPT>
</HEAD>
<BODY bgcolor="white" onLoad="getValues();">
<H1 align="center">Shopping Cart Checkout<HR noshade size="1"></H1>
<BLOCKQUOTE>
<p>The items you selected are displayed below. If you are happy with this selection then please enter your
personal details and submit the form below.
</BLOCKQUOTE>
<DIV align="center">
<TABLE border="1" cellpadding="5" cellspacing="0">
<TR>
<TH align="left">Name of the Product</TH>
<TH>No.</TH>
<TH>Unit Cost</TH>
<TH>Change Qty</TH>
<TH>Delete</TH>
<TH>Subtotal</TH>
</TR>
<SCRIPT>
var start = "<TR align='center'>\n<TH align='left'>";
var mid = "</TH>\n<TD>\n\n";
var end = "</TD>\n</TR>\n";
if (purse) document.write(start + "Leather Purse" + mid + purse + mid + "$20.00" + mid + "$" + (purse * 20) + ".00" + end);
if (shoes) document.write(start + "Leather Shoes" + mid + shoes + mid + "$25.00" + mid + "$" + (shoes * 25) + ".00" + end);
if (sandals) document.write(start + "Leather Sandals" + mid + sandals + mid + "$15.00" + mid + "$" + (sandals * 15) + ".00" + end);
if (wallet) document.write(start + "Leather Wallet" + mid + wallet + mid + "$10.00" + mid + "$" + (wallet * 10) + ".00" + end);
document.write("<TR><TH colspan='5' align='right'>Total:</TH><TH>$" + total + ".00</TH></TR>");
</SCRIPT>
</TABLE>
<FORM name="submitForm" method="get" onSubmit="alert('This is a demonstration only'); return false;">
<INPUT name="purse" type="hidden" value="0">
<INPUT name="shoes" type="hidden" value="0">
<INPUT name="sandal" type="hidden" value="0">
<INPUT name="wallet" type="hidden" value="0">
<INPUT name="total" type="hidden" value="0">
<TABLE border="0" cellpadding="5" cellspacing="0">
<TR><TH align="right">Name:</TH><TD><INPUT name="Name" type="text" size="40"></TD></TR>
<TR><TH align="right">Address:</TH><TD><INPUT name="Address" type="text" size="40"></TD></TR>
<TR><TH colspan="2"><INPUT type="button" value="View Cookies" onClick="alert('Cookie: ' + document.cookie);"> <INPUT type="submit" value="Submit Order"></TH></TR>
</TABLE>
</FORM>
</DIV>
---------------------------------------------------
Help would be appreciated
thanks
dave
Q. The main question is , I want to add features like delete and/or change the qty of a selected item, how do I do that ?
------------------------------------------------------------------
<SCRIPT>
function deleteCookie (name, path, domain) {
if (getCookie(name)) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}
function getCookie(name) {
var prefix = name + "=";
var begin = document.cookie.indexOf(prefix);
if (begin == -1) return null;
var end = document.cookie.indexOf(";", begin);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin + prefix.length, end));
}
function setCookie(name, value, expires, path, domain, secure) {
document.cookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
var purse = getCookie("purse");
if (!purse) purse = 0;
var shoes = getCookie("shoes");
if (!shoes) shoes = 0;
var sandals = getCookie("sandals");
if (!sandals) sandals = 0;
var wallet = getCookie("wallet");
if (!wallet) wallet = 0;
var total = 20 * purse + 25 * shoes + 15 * sandals + 10 * wallet;
function getValues() {
with (document.submitForm) {
purse.value = purse;
shoes.value = shoes;
sandals.value = sandals;
wallet.value = wallet;
total.value = total;
}
}
</SCRIPT>
</HEAD>
<BODY bgcolor="white" onLoad="getValues();">
<H1 align="center">Shopping Cart Checkout<HR noshade size="1"></H1>
<BLOCKQUOTE>
<p>The items you selected are displayed below. If you are happy with this selection then please enter your
personal details and submit the form below.
</BLOCKQUOTE>
<DIV align="center">
<TABLE border="1" cellpadding="5" cellspacing="0">
<TR>
<TH align="left">Name of the Product</TH>
<TH>No.</TH>
<TH>Unit Cost</TH>
<TH>Change Qty</TH>
<TH>Delete</TH>
<TH>Subtotal</TH>
</TR>
<SCRIPT>
var start = "<TR align='center'>\n<TH align='left'>";
var mid = "</TH>\n<TD>\n\n";
var end = "</TD>\n</TR>\n";
if (purse) document.write(start + "Leather Purse" + mid + purse + mid + "$20.00" + mid + "$" + (purse * 20) + ".00" + end);
if (shoes) document.write(start + "Leather Shoes" + mid + shoes + mid + "$25.00" + mid + "$" + (shoes * 25) + ".00" + end);
if (sandals) document.write(start + "Leather Sandals" + mid + sandals + mid + "$15.00" + mid + "$" + (sandals * 15) + ".00" + end);
if (wallet) document.write(start + "Leather Wallet" + mid + wallet + mid + "$10.00" + mid + "$" + (wallet * 10) + ".00" + end);
document.write("<TR><TH colspan='5' align='right'>Total:</TH><TH>$" + total + ".00</TH></TR>");
</SCRIPT>
</TABLE>
<FORM name="submitForm" method="get" onSubmit="alert('This is a demonstration only'); return false;">
<INPUT name="purse" type="hidden" value="0">
<INPUT name="shoes" type="hidden" value="0">
<INPUT name="sandal" type="hidden" value="0">
<INPUT name="wallet" type="hidden" value="0">
<INPUT name="total" type="hidden" value="0">
<TABLE border="0" cellpadding="5" cellspacing="0">
<TR><TH align="right">Name:</TH><TD><INPUT name="Name" type="text" size="40"></TD></TR>
<TR><TH align="right">Address:</TH><TD><INPUT name="Address" type="text" size="40"></TD></TR>
<TR><TH colspan="2"><INPUT type="button" value="View Cookies" onClick="alert('Cookie: ' + document.cookie);"> <INPUT type="submit" value="Submit Order"></TH></TR>
</TABLE>
</FORM>
</DIV>
---------------------------------------------------
Help would be appreciated
thanks
dave