close ad
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues


multi condition javascript for 2 different country select lists

Thread began 9/02/2013 9:01 pm by Christopher West | Last modified 9/03/2013 11:14 am by Jason Byrnes | 786 views | 1 replies |

Christopher WestCommunity Expert

multi condition javascript for 2 different country select lists

Hi, need a little help on coding a javascript code snippet that Ray helped me with a while back..I want to adapt on it to allow a client request.

I will describe the current checkout page then describe what I need to add.

The customer gets to the checkout page, where they can enter their address details, there is a select list for countries and a select list for delivery options. if the customer selects United Kingdom then the delivery options select list will allow the customer to select either; standard deivery, recorded delivery or special delivery. if the customer selects ANY other country then the delivery options select list is disabled (because the client doesnt want to provide any delivery options as they just want to use a default delivery charge thats automatically created elsewhere on the page based on that countries cost)...all works perfectly.....

now what I would like to add is an "alternative delivery address" to explain a little how this works; a customer can enter their intial address where they can order a kit (or a product and kit at the same time)...which the client sends outthe kit to the customer (this is free delivery as the kit is required to produce fingerprints for jewelry)...then the customer uses the kit sends back to the client and the client makes the jewelry and then sends the finished product to the the customer may be living in the UK so the kit gets sent to them...but the customer may want the finished product be sent to a friend or relative in another country....So I need a way to expland on my checkout form to allow for this...I am sure there are a number of ways to do this...I was even thinking of putting both the ID of the countries for both the countries select lists into a session then use PHP to calculate which is the greater delivery cost as that approach could make sense...Or I could put another checkbox on the checkout form where the customer would tick the box if they wish for the end product to be sent to an alternative address and I could use the ID of this check box to chose the session store for either the buyers address or the alternative address...I just need help to impliment this...

I am pasting and attaching the code to help with my question...



Here is the javascript:

function filterTypes() {
var parent = document.getElementById("buyercountry");
var child = document.getElementById("shippingoptions");
if (parent.options[parent.selectedIndex].value != "GB") {
child.selectedIndex = 0;
child.disabled = true;
} else {
child.disabled = false;

Here is the first and second form select list segments:

<label>Country</label><select name="buyercountry" class="inputbrd [required, Required]" onchange="filterTypes()" id="buyercountry"  value="<?php echo $row_rsUser['UserCountry']; ?>">

<label>Country</label><select name="shippingcountry" class="inputbrd" onchange="filterTypes()" id="shippingcountry"  value="">

Heres the session variables I am setting up:

...various recordsets etc etc...

$selcountry_ShipCost = "";
if (isset($_POST["country"])) {
$selcountry_ShipCost = $_POST["country"];
$seltype_ShipCost = "";
if (isset($_POST["shippingoptions"])) {
$seltype_ShipCost = $_POST["shippingoptions"];
$cartweight_ShipCost = "1";
if (isset($_GET["CartWeight"])) {
$cartweight_ShipCost = $_GET["CartWeight"];

mysql_select_db($database_dinkydb, $dinkydb);
$query_ShipCost = sprintf("SELECT shippingcosts.* FROM shippingcosts INNER JOIN shippinglocation on ShippingLocationZone = ShippingCostZone WHERE ShippingCode = %s AND ShippingCostsType = %s AND ShippingCostsWeightTo >= %s ORDER BY ShippingCostsWeightTo ", GetSQLValueString($selcountry_ShipCost, "text"),GetSQLValueString($seltype_ShipCost, "text"),GetSQLValueString($cartweight_ShipCost, "int"));
$ShipCost = mysql_query($query_ShipCost, $dinkydb) or die(mysql_error());
$row_ShipCost = mysql_fetch_assoc($ShipCost);
$totalRows_ShipCost = mysql_num_rows($ShipCost);


if (isset($_POST["country"]) && $_POST["country"] != "GB") $_POST["shippingoptions"] = "Standard Delivery";

$_GET["CartWeight"] = $DinkyCart->TotalColumn("TotalWeight");

if ($row_ShipCost) $_SESSION["ShipRate"] = $row_ShipCost["ShippingCostsValue"];

if (!session_id()) session_start();
$_SESSION["BuyerCountry"] = "".((isset($_POST["buyercountry"]))?$_POST["buyercountry"]:"") ."";

if (!session_id()) session_start();
$_SESSION["ShippingCounty"] = "".((isset($_POST["shippingcounty"]))?$_POST["shippingcounty"]:"") ."";
Sign in to reply to this post

Jason ByrnesWebAssist

You question is asking for custom development help, we offer custom development assistance through our premiere support service.

your question really goes beyond the scope of this support forum.

I think I Would use a checkbox to allow the user to enter the alternative shipping address, and use javascript to show or hide the alternative shipping fields.

then use PHP variables and store the Alternative shipping values if the alternative shipping option is selected or the initial shipping values if it is not. then use those variables in your recordset to look the shipping cost.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question





Ease of use


security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...