473,791 Members | 3,111 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tricky Addition Question In Javascript...Pl ease 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 TemporaryShippi ng = 0;

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

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

if ((document.Form .Item3.selected Index == 1) ||
(document.Form. Item3.selectedI ndex == 2) ||
(document.Form. Item3.selectedI ndex == 3))
{
NewQuantity3="T rue";
}
else
{
NewQuantity3="F alse";
}

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

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

Tim
Jul 20 '05 #1
1 1999
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,whi ch) {
lastSelected = lastItemArray[which]
if ((what.selected Index>0 && what.selectedIn dex<4) &&
!(lastSelected> 0 && lastSelected<4) ) {
ShippingTotal+= 7;
}
else if ((what.selected Index<1 || what.selectedIn dex>3) &&
(lastSelected<1 || lastSelected>3) ) {
ShippingTotal-=7;
}
if (ShippingTotal< 0) {
ShippingTotal=0 ;
}
document.Form.S hipping.value = ShippingTotal;
lastItemArray[which]=what.selectedI ndex;
}
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
1913
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 b, Column c) Table3 (Column a, Column b, Column c) Table1 contains a row of value (1, 2, 3)
3
2306
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. What I want to do now is setup some kind of javascript event so that when the user mouse's over a row the row changes colour to highlight it. I've discovered however that I can only change the row into one specific colour, and then back again into...
3
1846
by: Andy | last post by:
Hi, I am complete JavaScript novice and would really appreciate some help with this code: ===================================================================== <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> <!--#include file="Connections/ssdb.asp" -->
5
1636
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 this. assume I have it stored as such i have two dimensional array ball:
7
1492
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. However in this code (click event of the button), i'm processing an online payment, which takes about 5 seconds. While waiting for the payment to be processed, the user can click again on the button, and this is what i want to block. I want to...
6
1486
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 the text betwen "document.form1." and ".select ()".
9
1725
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 type="text/javascript">
9
2360
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 "using { Pen mypen = new Pen(Color.Black, 1)) {}), which I think makes a difference: I find the following assignment does not work: //myPenTest instantiated in the normal constructor, as was baseline,
3
1769
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 filter uppercases every alphabetic character and then the second filter replaces every 'E' with "#'. OK, very nice. What's trivial about these examples is that the returned string is exactly the same length as the string which is actually read...
0
9669
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9517
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10156
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9997
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5435
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.