473,503 Members | 1,768 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tricky Addition Question In Javascript...Please help. TIA

Tim
Hello,

I'm extremely puzzled; I cannot figure out what I'm doing wrong. Here's
the situation. I would really appreciate any suggestions.

I'm modifying a shopping cart in the following way. I've just added new
prices to several drop-downs on our javascript-based ordering page. These
new prices must have shipping costs added to them at the bottom of the
ordering system in a text box called "Shipping", while the existing prices
do not have to have shipping costs added.

Basically this means that if the user selects the first 3 options in the
drop-down boxes, the text box of "Shipping" must show "7.00", but if any
option after that is selected, the text box of "Shipping" must show "0.00".
Oh, and here's another wrinkle: only certain drop-down boxes will need this
modification. Also, if a customer selects more than one of these "7.00"
items, an additional "7.00" must be added to their shipping costs.

Any suggestions on how to best implement this? I've tried the following
code, but it isn't working--specifically, I can't the shipping to be
properly affected if a users should move from a "7.00 Shipping" option to a
"0.00" option..

var ShippingTotal = 0;
var ShippingAdded = 7;
var TemporaryShipping = 0;

var NewQuantity1 = "False";
var NewQuantity3 = "False";

....[this is the same code for all drop-down boxes]

if ((document.Form.Item3.selectedIndex == 1) ||
(document.Form.Item3.selectedIndex == 2) ||
(document.Form.Item3.selectedIndex == 3))
{
NewQuantity3="True";
}
else
{
NewQuantity3="False";
}

if (NewQuantity3=="True")
{
ShippingTotal += ShippingAdded;
document.Form.Shipping.value = ShippingTotal;
}
else if (NewQuantity3=="False")
{
document.Form.Shipping.value = ShippingTotal;
}

Again, any help would be greatly appreciated. Thanks in advance.

Tim
Jul 20 '05 #1
1 1980
jon
It's a darn tricky problem. Good workout. I did this (which assumes
you are using onChange events and that there is a "none" option at
index 0 for all boxes)

var ShippingTotal = 0;

//arrayItem for every selectbox to store last index selected

var lastItemArray = new Array();
lastItemArray[0] = 0;
lastItemArray[1] = 0;
lastItemArray[2] = 0;

// onChange event function for all select boxes (only one function)
// what is form element object
// which is id num manually passed in for array

function reCalc(what,which) {
lastSelected = lastItemArray[which]
if ((what.selectedIndex>0 && what.selectedIndex<4) &&
!(lastSelected>0 && lastSelected<4)) {
ShippingTotal+=7;
}
else if ((what.selectedIndex<1 || what.selectedIndex>3) &&
(lastSelected<1 || lastSelected>3)) {
ShippingTotal-=7;
}
if (ShippingTotal<0) {
ShippingTotal=0;
}
document.Form.Shipping.value = ShippingTotal;
lastItemArray[which]=what.selectedIndex;
}
Arrays are useful. Hope that helps.

jon

http://www.gurupika.com/
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1898
by: Bung | last post by:
Hi, I have a tricky sql statment I have to write (tricky for me) and I am stuck. I'm having trouble with the following problem. Table1 (Column a, Column b, Column c) Table2 (Column a, Column...
3
2281
by: Colin Steadman | last post by:
Help! I'm a stupid HTML bod and I dont do Javascript! I have a grey coloured table that displays certain columns in either red, green or orange to give meaning and emphasis to certain data. ...
3
1828
by: Andy | last post by:
Hi, I am complete JavaScript novice and would really appreciate some help with this code: ===================================================================== <%@LANGUAGE="VBSCRIPT"...
5
1618
by: Danny | last post by:
Hi there I need help with a tricky problem. I have a 2 dimensional array with qualities such as ball size, ball color, ball weight. Now I have to print out all the possible combinations of...
7
1471
by: Matt | last post by:
Hello, In an aspx page i have webform with some textboxes and a simple button. When the button is clicked, there is a postback and then the code in the click event of the button is executed. ...
6
1472
by: localhost | last post by:
I have a string that looks like this: "document.form1.textBox1.focus ();document.form1.textBox1.select();" I want to replace the text between "document.form1." and ".focus()", as well as...
9
1711
by: howachen | last post by:
Hi, I have one very simple tricky question which is quite interesting, I would like to share with all of you here... //======================================= <script...
9
2340
by: raylopez99 | last post by:
Just an observation: pens for drawing lines in Win Forms are tricky when assignment is inside the paint handler. inside of the Paint handler, but not inside a "using" brace (that is, outside of...
3
1764
by: Joseph Geretz | last post by:
I'm using the Request Filter documentation which can be found here: http://msdn.microsoft.com/en-us/library/system.web.httprequest.filter.aspx In this example, two filters are installed, one...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7076
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7274
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5576
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3151
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
377
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.