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]ItemA: ItemA:medium @ 4
Price: $4
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]ItemB: ItemB:18
Price: $2
The [B]correct
[B]ItemB: ItemB:18″ @ 4
Price: $4
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)
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
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!!