2 Replies - 5389 Views - Last Post: 09 March 2009 - 06:57 AM

#1 TechWar  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 470
  • Joined: 17-February 09

help with shopping cart - remove items

Post icon  Posted 06 March 2009 - 10:38 AM

<html>
<script language="javascript">
<!-- Hide from older browsers
var numItems=0
var ShoppingCart=new Object

top.MAIN.document.onkeypress=top.HIDDEN.keyPressed
top.MAIN.focus()

function addItem(Description, Price, ItemNum){
	this.Description=Description
	this.Price=Price
	this.ItemNum-ItemNum
	this.display=printItem
	return this
}

function addtoCart(Description,Price){
	ShoppingCart[numItems]=new addItem(Description, Price, numItems)
	numItems=numItems+1
	alert(Description+" has been added to your shopping cart.")
}

function deleteItem(ItemNum){
	delete ShoppingCart[ItemNum]
	viewCart()
}

function printItem(deleteFlag,TargetDocument){
	with(TargetDocument){
		write("<tr><td>"+this.Description+"</td>")
		write("<td align=right>$"+this.Price+"</td>")
		if(deleteFlag==true)
			write("<td><a href='java script:top.HIDDEN.deleteItem("+this.ItemNum+")'>Remove from Cart</a></td>")
		write("</tr>")
	}
}

function viewCart(){
	var cartTotal=0
	
	with(top.MAIN.document){
		write()
		close()
		write("<html><title>Val-u Computers Shopping Cart</title>")
		write("<body BGCOLOR=#AODOEO><center>")
		write("<table border=0><tr>")
		write("<td><img src=comp2.jpg></td>")
		write("<td align=center, valign=bottom>")
		write("<h2>Val-u Computers Shopping Cart</h2></td>")
		write("<td><img src=comp3.jpg></td></tr>")
		write("</table>")
		write("<br /><hr /><br />")
		write("<table border=1 cellpadding=3 cellspacing=1 width=500 BGCOLOR=LIGHTYELLOW>")
		
		for(i in ShoppingCart){
			cartTotal=cartTotal+ShoppingCart[i].Price
			if (ShoppingCart[i].ItemNum != "")
				ShoppingCart[i].display(true,top.MAIN.document)
		}
		
		write("<tr><td>Total:</td><td align=right>$"+cartTotal+"</td>")
		write("<td> </td></tr></table><br />")
		write("<a href='java script:top.HIDDEN.goBack();'>Return to Order Page</a><br /><br />")
		write("<a href='java script:top.HIDDEN.printOrder();'>Display printable Order Form</a>")
		write("<br /></center></body></html>")
	}
}
function goBack(){
	top.MAIN.history.go(-1)
}



function printOrder(){
	var CartTotal=0
	var Name=""
	var CustomerID=""
	var PhoneNumber=""
	
	Name=prompt("Enter your name:","")
	customerID=prompt("Enter your customer ID:","")
	PhoneNumber=prompt("Enter your phone number:","")
	
	alert("To print your order, click file on the menu bar and then click print. When you are finished printing, you may close this window.")
	order=window.open("","orderWindow","toolbar=no,width=550,height=400,status=no,menubar=yes,resize=yes")
	
	with(order.document){
		write()
		close()
		
		write("<html>")
		write("<title>Val-U Computers Order Form</title><body BGCOLOR=WHITE>")
		write("<table border=0>")
		write("<tr><td><img src=comp4.jpg></td>")
		write("<td align=center valign=bottom>")
		write("<h2>Val-U Computers Order Form</h2></td>")
		write("<td><img src=comp5.jpg></td></tr></table>")
		write("Fax this form to Val-U Computers at 555-3423.<br />")
		write("Your Name: "+Name+"<br />")
		write("Your Customer ID: "+customerID+"<br />")
		write("Your Phone Number: "+PhoneNumber+"<br /><br />")
		write("<center><table border=1 cellpadding=1 cellspacing=3 width=350>")
		
		for (i in ShoppingCart){
			CartTotal=CartTotal+ShoppingCart[i].Price
			if (ShoppingCart[i].ItemNum!="")
				ShoppingCart[i].display(false,order.document)
		}
		
		write("<tr><td>Total</td><td align=right>$"+CartTotal+"</td></tr>")
		write("</table>")
		write("</center></body></html>")
		close()
	}
}

function keyPressed(key){
	var sentString=""
	
	if(navigator.appName=="Netscape"){
		var keyChar=new Number(key.which)
		sentString=sentString+unescape("%"+keyChar.toString(16))
		if(sentString=="v" || sentString=="V")
			viewCart()
	}
	if (navigator.appName=="Microsoft Internet Explorer"){
		sentString=sentString+String.fromCharCode(top.MAIN.window.event.keyCode)
		if (sentString=="v" || sentString=="V")
			viewCart()
	}
}

//-->
</script>

</html>


My problem is that, when the page is printed showing the current order, there is a 'click to remove item' that is not removing the item. when hovering over the link, it shows ShoppingCart(ItemNum), but shows ItemNum as undefined. It has to be in the viewCart() function somewhere but after 2 days, I still can't figure it out.
When it drew the table originally, it wasn't showing the items at all, just the total price, and I fixed that by putting "" instead of null(took me a while to figure that one out to)

If someone could point me in the right direction, I would greatly appreciate it. Maybe give me a gerneral area or a general idea of what to look for to solve this.
Thanks

P.S.
If you need to code for the other 2 pages, I'll post them, but, I don't think they're relevant here...

Is This A Good Question/Topic? 0
  • +

Replies To: help with shopping cart - remove items

#2 roudard  Icon User is offline

  • D.I.C Head

Reputation: 17
  • View blog
  • Posts: 143
  • Joined: 26-September 05

Re: help with shopping cart - remove items

Posted 09 March 2009 - 05:33 AM

Hi, in this function :
function addItem(Description, Price, ItemNum){
	this.Description=Description;
	this.Price=Price;
	this.ItemNum-ItemNum;  /// should be this.ItemNum=ItemNum
	this.display=printItem;
	return this;
}


this.ItemNum is not initialised properly.
That would explain why it is undefined when you call it in this.display().

Hope this helps
Was This Post Helpful? 1
  • +
  • -

#3 TechWar  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 470
  • Joined: 17-February 09

Re: help with shopping cart - remove items

Posted 09 March 2009 - 06:57 AM

It sure does, thanks so much for your help!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1