/    Sign up×
Community /Pin to ProfileBookmark

Javascript problem, please help!

[FONT=Arial]Hi, i am currently learning to do a very basic shopping cart. The task is to add options from a drop down menu such as size or colour to the cart.

I have tried all the ways i know off but i keep getting errors.

To add an item to the cart via a link i use this…
<a href=”javascript:additem(‘description’, ‘colour’, ‘size’, ‘price’,’qty’);”>

the colour and the size bits is where i am having problems, i have a drop down list for each item being the colour and size but i do not know how to include it so show on the cart itself.

Here is the current bit of code i have to add it to the columns…

Code:
write(“<TD>” + items[i].desc);
write(“<TD>” + items[i].col); <– the colour which shows on the cart just shows ‘colour’ from the <a href link
write(“<TD>” + items[i].size); <– the size which shows on the cart just shows ‘colour’ from the <a href link
write(“<TD>£” + items[i].price);
write(“<TD>£” + (items[i].price * items[i].quantity));

If anyone has any ideas of how I can do this please could you let me know as I would be very greatful!

Thanks in advanced,
Marc ? [/FONT]

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterApr 05.2005 — Would ya mind showing us your function(s)?
Copy linkTweet thisAlerts:
@marc_2kyauthorApr 05.2005 — Hi, here is the shopping cart script...

&lt;SCRIPT LANGUAGE="JavaScript"&gt;
var items = new Array(10);
var numitems = 0;
var col
var size
function Item(d,col,size,c,q) {
this.desc = d;
this.col = col;
this.size = size;
this.price = c;
this.quantity = q;
}
&lt;/SCRIPT&gt;


and here is the html where a product is...
<i>
</i>Size:&lt;/strong&gt;&lt;/div&gt;&lt;/td&gt;
&lt;td colspan="2"&gt;&lt;select name="additional-info" id="select" style="font-family: Verdana; font-size: 8pt"&gt;
&lt;option value="None"&gt;&lt;/option&gt;
&lt;option value="Small"&gt;Small&lt;/option&gt;
&lt;option value="Medium"&gt;Medium&lt;/option&gt;
&lt;option value="Large"&gt;Large&lt;/option&gt;
&lt;option value="X Large"&gt;X Large&lt;/option&gt;
&lt;option value="XXL"&gt;XXL&lt;/option&gt;
&lt;/select&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;div align="right"&gt;&lt;strong&gt;Colour:&lt;/strong&gt;&lt;/div&gt;&lt;/td&gt;
&lt;td colspan="2"&gt;&lt;select name="select" id="select2" style="font-family: Verdana; font-size: 8pt"&gt;
&lt;option value="None"&gt;&lt;/option&gt;
&lt;option value="Red"&gt;Red (as shown)&lt;/option&gt;
&lt;option value="Blue"&gt;Blue&lt;/option&gt;
&lt;option value="Green"&gt;Green&lt;/option&gt;
&lt;option value="Orange"&gt;Orange&lt;/option&gt;
&lt;/select&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;div align="right"&gt;&lt;span class="style3"&gt;&lt;span class="style4"&gt;RRP:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;
&lt;td colspan="2"&gt;&lt;div align="left"&gt;&lt;span class="style3"&gt;&lt;s&gt;&amp;pound;89.99&lt;/s&gt;&lt;/span&gt;&lt;span class="style3"&gt;&lt;span class="style4"&gt; &lt;br&gt;
&lt;/span&gt;&lt;span class="style7"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;div align="right"&gt;&lt;span class="style3"&gt;&lt;span class="style4"&gt;NOW:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;
&lt;td width="119"&gt;&lt;div align="left"&gt;&lt;span class="style3"&gt;&lt;span class="style9"&gt;&lt;u&gt;&amp;pound;59.99&lt;/u&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;
&lt;td width="134"&gt;&lt;div align="right"&gt;&lt;span class="style3"&gt;&lt;span class="style7"&gt;&lt;u&gt;&lt;img src="images/add.gif" name="cart_button" width="133" height="51" border="0" id="cart_button"&gt;&lt;/a&gt;&lt;/u&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;


Basically where the sizes and colours are on the html form, I need them to appear on the shopping cart script where i have col and size. If you copy and paste the script to a html file you should see it working.

If you could help me, or know another way of doing this please let me know.

Thanks,

Marc
Copy linkTweet thisAlerts:
@UltimaterApr 05.2005 — [code=html]
<!-- -- -->
<a href="javascript:additem('Race Face Jacket', document.getElementById('select2').options[document.getElementById('select2').selectedIndex].value, document.getElementById('select').options[document.getElementById('select').selectedIndex].value, '59.99','1');"><img src="images/add.gif" name="cart_button" width="133" height="51" border="0" id="cart_button"></a>
<!-- -- -->
[/code]
Copy linkTweet thisAlerts:
@marc_2kyauthorApr 05.2005 — ? thanks Ultimater, you don't know how happy you made me ?

I've spent all day on this.

Thanks again!

Marc
Copy linkTweet thisAlerts:
@UltimaterApr 05.2005 — Your welcome!

If you don't mind, would you also sign my guestbook? [url=http://ultimiacian.tripod.com/guestbook.html]http://ultimiacian.tripod.com/guestbook.html[/url]

No peaking at the previous entries prior to signing! ?
Copy linkTweet thisAlerts:
@marc_2kyauthorApr 05.2005 — done ?
Copy linkTweet thisAlerts:
@UltimaterApr 05.2005 — Hmm, I should really add another box in my guestbook for the user's WebDeveloper Forums user name.

Your entry is appricated!
×

Success!

Help @marc_2ky 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,
)...