473,387 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Function with pop up menu

I have a shopping cart script with a pop up menu for the shipping
variables. I have two options at present, option 0, standard 'UK
Delivery' charge rate, option 1, for 'Collect'. The default is option
0.

I would like to add a third for 'Free Delivery' (which I have added).

However the option should only be available and selectable when the
sub total of the order is 75.00 or more. The option on the pop up
should also default to 'Free Delivery' when this amount or more is
reached. Like wise the 'Free Delivery' option should not be selectable
on amounts of 74.99 or less. Is this possible?

Can anybody help as this is a little beyond my scripting ability. Many
thanks.

This is the shipping function from the code.
// ****Start of code section to display totals****
// ****and shipping/handling select box.****

function writeShipping() {

leng = 3;
options = new Array(leng);
options[0] = "UK Delivery";
options[1] = "Collect";
options[2] = "Free Delivery";

// **Begin code section for order totals calculations**

var shipCost = 0

// **Shipping charges.**
// **These definitions correspond to the shipping select**
// **options defined in the writeShipping() function.**

function shippingCost() {
shipCost = 0
itemUp = counter - 1 // variable to increment charges
multiplier = .5 // additional charge per item after first.
if (document.shopCart.ShipVia.options[0].selected) {
shipCost = 5.95 } // Standard Delivery
if (document.shopCart.ShipVia.options[1].selected) {
shipCost = 0.00 } // Collect
if (document.shopCart.ShipVia.options[2].selected) {
shipCost = 0.00 } // Free Delivery

}

*/

document.shopCart.shippingcharge.value = fix(with_Shipping)
transaction_amount = sub_total + with_Shipping
{
document.shopCart.transactionamount.value = fix(transaction_amount)
}
}
}
Jul 23 '05 #1
2 1108
Paul Taylor wrote:
I have a shopping cart script with a pop up menu for the shipping
variables. I have two options at present, option 0, standard 'UK
Delivery' charge rate, option 1, for 'Collect'. The default is option
0.

I would like to add a third for 'Free Delivery' (which I have added).

However the option should only be available and selectable when the
sub total of the order is 75.00 or more. The option on the pop up
should also default to 'Free Delivery' when this amount or more is
reached. Like wise the 'Free Delivery' option should not be selectable
on amounts of 74.99 or less. Is this possible?

Can anybody help as this is a little beyond my scripting ability. Many
thanks.
Apparently. The code you have posted doesn't do much, it just sets up
some variables. Provide a link to the page and perhaps something can
be done, otherwise there simply isn't enough here to go on.

[...] function writeShipping() {

leng = 3;
options = new Array(leng);
options[0] = "UK Delivery";
options[1] = "Collect";
options[2] = "Free Delivery";

// **Begin code section for order totals calculations**

var shipCost = 0

// **Shipping charges.**
// **These definitions correspond to the shipping select**
// **options defined in the writeShipping() function.**

function shippingCost() {
shipCost = 0
Why initialise shipCost again?
itemUp = counter - 1 // variable to increment charges
Where is "counter" initialised/given a value?
multiplier = .5 // additional charge per item after first.
Does "multiplier" need to be global?
if (document.shopCart.ShipVia.options[0].selected) {
shipCost = 5.95 } // Standard Delivery
if (document.shopCart.ShipVia.options[1].selected) {
shipCost = 0.00 } // Collect
if (document.shopCart.ShipVia.options[2].selected) {
shipCost = 0.00 } // Free Delivery
Surely it would be better to grab the ShipVia elements, then iterate
through them to find out which is selected? And if the options are
given a value of the shipping cost, you get it from there so you only
maintain the value in one place.

A better way of writing the above is:

var fElements = document.forms['shopCart'].elements['ShipVia'];
for (var i=0; i<fElements.length; i++) {
if (fElements[i].selected) {
shipCost = fElements[i].value;

// This is a debug line, you don't want it in the finished code
alert('Selected: ' + i + ' cost $' + shipCost);
}
}

The related HTML may look like:
<form name="shopCart">
<select name="ShipVia">
<option value="5.95">Standard Delivery<br>
<option value="0.00">Collect<br>
<option value="0.00">Free Delivery<br>
</select>
<input type="button" value="Click me" onclick="shippingCost();">
</form>

Of course I would do shippingCost(this.form) to save myself having to
hard-code the form name in the shippingCost function, but that's up to
you.

Of course, when you get this at the server you have to do all this work
again just in case the user has spoofed your input page...

}

*/

document.shopCart.shippingcharge.value = fix(with_Shipping)
Presumably there is a function fix() somewhere?
Where is "with_Shipping" initialised/given a value?
transaction_amount = sub_total + with_Shipping
{
document.shopCart.transactionamount.value = fix(transaction_amount)
}
}
}


Does "transaction_amount" need to be global?
Where is "sub_total" initialised/given a value?

At some point somewhere you have worked out subtotal. At that point you
can enable/disable your shipping options depending on the value of the
sub_total:

if (sub_total >= 75) {
document.forms['shopCart'].elements['ShipVia'].options[2].enabled = true;
document.forms['shopCart'].elements['ShipVia'].options[0].enabled = false;
} else {
document.forms['shopCart'].elements['ShipVia'].options[2].enabled = false;
document.forms['shopCart'].elements['ShipVia'].options[0].enabled = true;
}

All totally untested of course, since I have absolutely nothing to test
against. Please don't implement this on a commercial site until you
are utterly certain of what you are doing and all entries and values
are verified on the server - or you will be ripped-off.

Have fun - Fred.
Jul 23 '05 #2
Fred Oz wrote:
if (sub_total >= 75) {
document.forms['shopCart'].elements['ShipVia'].options[2].enabled = true;
document.forms['shopCart'].elements['ShipVia'].options[0].enabled = false;
} else {
document.forms['shopCart'].elements['ShipVia'].options[2].enabled = false;
document.forms['shopCart'].elements['ShipVia'].options[0].enabled = true;
}


Oooops, the above will only work if ShipVia is a set of radio buttons
or check boxes, not options.

Fred.
Jul 23 '05 #3

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

Similar topics

5
by: kazack | last post by:
I am a little confused with code I am looking at. My c++ book does not go into passing a structure to a function so I pulled out a c book which does. and I do not understand the prototype verses...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
1
by: Foxy Kav | last post by:
Hi everyone, im a first year UNI student doing a programming subject and im stuck on how to get rid of my global variables, char stringarray and char emptystring. I was wondering if anyone could...
3
by: Ken | last post by:
hello, I would to know if it is possible to call an object in a function within a class. Meaning , In a class, A function X calling onto a function Y, and function Y we want one of the two...
1
by: Lazlo Woodbine | last post by:
I'm trying to implement a dynamic menu using CSS/DHTML/JavaScript. The menu bar is implemented as hyperlinks so I can use the :hover :active etc. pseudo-styles. When moving from one item to...
3
by: Richard Hollenbeck | last post by:
Back in the old days before I started learning about menubars (the day before yesterday,) I based all my operations on command buttons on the forms. Now the forms are all cluttered up with buttons...
18
by: ramu | last post by:
Can anyone tell me the advantages of using function pointers? Thanks in advance.
4
by: hanseymoon | last post by:
Dear newsgroup: I've got this long function, which works good overall to spell check words from a dictionary and I am not in a position to replace it. Can someone please see where or how it...
3
by: tomPee | last post by:
Hi, I have the following problem: I am trying to make some sort of base class menu that i can then use to derive other menu's from. Those menu's should then be able to interact with each other....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...

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.