Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-12-2004, 07:40 PM   PM User | #1
HiEverybody
New Coder

 
Join Date: Jul 2004
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
HiEverybody is an unknown quantity at this point
Question Help with shopping cart?????

My friend gets the error message "object expected" when he clicks on the add to shopping cart link.

What is he doing wrong

Please Help???

Here is the code for the order page:

Code:

<html>
<head>
<title>Easy Credit Online Shopping</title>
<SCRIPT LANGUAGE = Javascript>

</SCRIPT>

</head>

<body bgcolor="#FFFFFF" text="#000000">
<div align="center">
<p><font size="5"><b>Welcome to the Easy Credit Online Shopping Site</b></font>
</p>
<p>&nbsp;</p>
</div>
<hr>
<p align="center">Press 'V' to view your Shopping cart or click <a href="cart.htm">here</a></p>
<table width="70%" border="1" align = "center">
<tr>
<td width="24%" height="37">T-Shirt</td>
<td width="66%" height="37" align="left" valign="middle">
<p align="left">Lime Green T-Shirt with Orange Easy Credit Logo - Small</p>
<p ><a href="javascriptlace('T-Shirt - Small')" align="left">Add to Shopping Cart</a></p>
</td>
<td width="10%" height="37">R29.50</td>
</tr>
<tr>
<td width="24%" height="37">T-Shirt</td>
<td width="66%" height="37" align="left" valign="middle">
<p align="left">Lime Green T-Shirt with Orange Easy Credit Logo -Medium</p>
<p ><a href="javascriptlace('T-Shirt - Medium')"align="left">Add to Shopping Cart</a></p>
</td>
<td width="10%" height="37">R34.50</td>
</tr>
<tr>
<td width="24%" height="37">T-Shirt</td>
<td width="66%" align="left" valign="middle">
<p align="left">Lime Green T-Shirt with Orange Easy Credit Logo - Large</p>
<p ><a href="javascriptlace('T-Shirt - Large')"align="left">Add to Shopping Cart</a></p>
</td>
<td width="10%">R39.50</td>
</tr>
<tr>
<td width="24%" height="37">Capp</td>
<td width="66%" align="left" valign="middle">
<p align="left">Adjustable Lime Green Cap with Orange Easy Credit Logo</p>
<p ><a href="javascriptlace('Lime Green Cap')"align="left">Add to Shopping Cart</a></p>
</td>
<td width="10%">R18.75</td>
</tr>
<tr>
<td width="24%" height="37">Capp</td>
<td width="66%" align="left" valign="middle">
<p align="left">Adjustable Orange Cap with Lime Green Cap Easy Credit Logo</p>
<p ><a href="javascriptlace('Orange Cap')"align="left">Add to Shopping Cart</a></p>
</td>
<td width="10%">R18.75</td>
</tr>
<tr>
<td width="24%" height="37">Easy Credit Teddy Bear</td>
<td width="66%" align="left" valign="middle">
<p align="left">25cm Tall Lime Green Teddy Bear with Orange T-shirt</p>
<p ><a href="javascriptlace('Teddy Bear')"align="left">Add to Shopping Cart</a></p>
</td>
<td width="10%">R66.50</td>
</tr>
</table>
<p align="center">E-mail us for more information: <a href="mailto:easycredit@hotmail.com">easycredit@hotmail.com</a></p>
</body>
</html>

Here is the code for the viewing of the shopping cart page:

Code:

<html>
<head>
<title>Easy Credit Online Shopping</title>
<SCRIPT LANGUAGE = Javascript>

var items_string = "";

function place(new_item)
{
items_string = items_string + "xxx" + new_item;
document.cookie = "items=" + escape(items_string);
}

"items=xxxT-Shirt - Small;xxxT-Shirt - Medium;xxxT-Shirt - Large;xxxLime Green Cap;xxxOrange Cap;xxxTeddy Bear;"
whole_items_cookie = "items=xxxT-Shirt - SmallxxxT-Shirt - MediumxxxT-Shirt - LargexxxLime Green CapxxxOrange CapxxxTeddy Bear";

if (whole_items_cookie !="")
{
items_array = whole_items_cookie.split("xxx");
items_array[0] = "items=";
items_array[1] = "T-Shirt - Small";
items_array[2] = "T-Shirt - Medium";
items_array[3] = "T-Shirt - Large";
items_array[4] = "Lime Green Cap";
items_array[5] = "Orange Cap";
items_array[6] = "Teddy Bear";

}

</script>


</head>

<body bgcolor="#FFFFFF" text="#000000">

<SCRIPT LANGUAGE = Javascript>

if(items_array != "")
{
for (i=1; i < items_array.length; i++)
{
document.write("<h3>" + items_array[i] + "</h3>");
}
}
</script>

</body>

</html>
HiEverybody is offline   Reply With Quote
Old 07-12-2004, 08:51 PM   PM User | #2
sad69
Senior Coder

 
Join Date: Feb 2004
Posts: 1,206
Thanks: 0
Thanked 0 Times in 0 Posts
sad69 is an unknown quantity at this point
Well it looks like 'Add to Shopping Cart' is a link. The 'webpage' it points to is: javascriptlace('Orange Cap'). (found in the href attribute...).

Now that looks somewhat bizarre right off the bat. So now that leads us to believe that your friend is trying to execute some Javascript, possibly trying to make a Javascript function call? Now what's the name of this function?

Is it: javascriptlace or lace?

In the href attribute, to make a Javascript call, you need to use the following prefix:
javascript:xxx(...)
Code:
<a href="javascript:lace('Orange Cap')" align="left">Add to Shopping Cart</a>
The alternative method is to do the following:
Code:
<a href="#" onclick="lace('Orange Cap');" align="left">Add to Shopping Cart</a>
Either way, after studying the provided code, there were no functions found. You have to create the function (whether it's javascriptlace or lace) before you can make a call to it.

Hopefully that helps, post back if you're still having problems. Also, wrap any and all code in [ code ][ /code ] tags (no spaces) and ensure proper indenting is applied (for our ease of reading..)

Sadiq.
sad69 is offline   Reply With Quote
Old 07-13-2004, 12:27 AM   PM User | #3
HiEverybody
New Coder

 
Join Date: Jul 2004
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
HiEverybody is an unknown quantity at this point
Thumbs up

It had to be place and not lace.

He has almost completed his shopping cart program.

Thanx for the tip on the [code] tags!

Thank You for your trouble and sorry about not using code tags

Cheers
HiEverybody is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:19 AM.


Advertisement
Log in to turn off these ads.