/    Sign up×
Community /Pin to ProfileBookmark

Javascript for shopping cart not passing correct values

Please, if someone can help me out it would be greatly appreciated!! I am new to javascript and have been wearing out my brain cells trying to figure this out???

The problem is that on a webpage, the item’s size with corresponding price does not transfer correctly to the shopping cart if the value of the size is a numeric value, but it works correctly if the size is a text value. Also, all item information is pulled from a database.

Ok, so take ItemA for example:
ItemA comes in Size:small for Price:$2 and Size:medium for Price:$4.
I choose the radio button for the medium item and click “add to cart”.
The cart [B]correctly[/B] reads as follows:
[B]ItemA: ItemA:medium @ 4
Price: $4[/B]

However, take ItemB for example:
ItemB comes in Size:16″ for Price:$2 and Size:18″ for Price:$4.
I choose the radio button for the 18″ item and click “add to cart”.
The cart reads [B]incorrectly [/B] reads as follows:
[B]ItemB: ItemB:18
Price: $2[/B]

The [B]correct[/B] cartdisplay for ItemB should be:
[B]ItemB: ItemB:18″ @ 4
Price: $4[/B]

The code from my page that I’m assuming pertains to this issue is posted below:
(The first section is the javascript code and the second section is the excerpt from the form.)

function ReadForm (obj1, tst) { // process radio and checkbox
var i,amt,des,obj,pos,val;
amt = obj1.baseamt.value*1.0; // base amount
des = obj1.basedes.value; // base description
for (i=0; i<obj1.length; i++) { // run entire form
obj = obj1.elements[i]; // a form element
if (obj.type == “checkbox” || // checkboxes
obj.type == “radio”) { // and radios
if (obj.checked) { // did user check it?
val = obj.value; // the value of the selection
pos = val.indexOf (“@”); // price set?
if (pos >= 0) amt = val.substring (pos + 1)
*
1.0;
pos = val.indexOf (“+”); // price increment?
if (pos >= 0) amt = amt + val.substring (pos + 1)*1.0;
pos = val.indexOf (“%”); // percent change?
if (pos >= 0) amt = amt + (amt *
val.substring (pos + 1)/100.0);
if (des.length == 0) des = val;
else des = des + “, ” + val; // accumulate value
}

<input name=”Size” type=”radio” id=”Size”
onclick=”ReadForm (this.form, false);”
value=”Size <%=(rsSelectItem.Fields.Item(“Prod_Size”).Value)%> @ <%=(rsSelectItem.Fields.Item(“Prod_Price”).Value)%>

Thank you!!

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceApr 17.2005 — However, take ItemB for example:

ItemB comes in Size:16" for Price:$2 and Size:18" for Price:$4.

I choose the radio button for the 18" item and click "add to cart".

The cart reads [B]incorrectly [/B] reads as follows:

[B]ItemB: ItemB:18

Price: $2[/B]
[/QUOTE]

First question... Have you verified that the HTML contains the correct values in this case?
Copy linkTweet thisAlerts:
@camels43authorApr 17.2005 — Yes, the correct values are actually pulled from a database, and in the database, the values are correct. The dynamic values are in bold below.

<input name="Size" type="radio" id="Size"

onclick="ReadForm (this.form, false);"

value="Size <%=([B]rsSelectItem.Fields.Item("Prod_Size").Value[/B])%> @ <%=([B]rsSelectItem.Fields.Item("Prod_Price").Value[/B])%>">
Copy linkTweet thisAlerts:
@phpnoviceApr 17.2005 — No, I mean the generated HTML that is seen by the browser -- not the original source.
Copy linkTweet thisAlerts:
@camels43authorApr 17.2005 — OH... sorry...

Yes, everything on the page loads correctly.

If you want to check it out, feel free to go to:

jgiftdesigns.com

Just go to the necklaces section and go through the process of adding one of the larger sizes to the cart. The sizes don't transfer with the prices, but they look correct on the page?

PS... thanks for taking the time to help me with this!! I really appreciate it!
Copy linkTweet thisAlerts:
@phpnoviceApr 18.2005 — OK, I found the problem and it is neither caused by nor fixable by JavaScript. See it?
[code=html]
<input name="Size" type="radio" id="Size"
onclick="ReadForm (this.form, false);"
value="Size 14" @ 24.95">
[/code]

Here's the fix, too:
[code=html]
<input name="Size" type="radio" id="Size"
onclick="ReadForm (this.form, false);"
value="Size <%=(Replace(rsSelectItem.Fields.Item("Prod_Size").Value, """", "&quot;")%> @ <%=(rsSelectItem.Fields.Item("Prod_Price").Value)%>">
[/code]
Copy linkTweet thisAlerts:
@camels43authorApr 18.2005 — Thanks for locating the problem ? It's always something simple eh??

I really appreciate your time!!
Copy linkTweet thisAlerts:
@phpnoviceApr 18.2005 — Now you know why I wanted to see the generated source. ?

Cheers.
×

Success!

Help @camels43 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 5.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...