Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change drop down values

Status
Not open for further replies.

antonyx6666

Programmer
Sep 9, 2010
38
GB
Hello, I have a drop down list on my form called DDPaddrType - let's call it Drop Down 1

Drop Down 1 - DDPaddrType
Code:
<select id="DDPaddrType" class="FormField" style="display:none;width:150px;" onChange="DDPaddrTypeChanged(this)" >
	<option>Please Select . . .</option>
	<option>Local Address</option>
</select>

Another <option> is added to this drop down list from a file called AddrShortcuts.js.inc. This extra <option> appears in the drop down list above as 'Heathrow Airport.' Below is the code in AddrShortcuts.js.inc which adds this <option>

AddrShortcuts.js.inc
Code:
// Place holder
var AS_Airport = 
    {
    group :
        "Heathrow Airport",

    premise:
        "Flight Number (eg VS401 Dubai)",

    shortcuts :
        [           

            ["HEATHROW TERMINAL 1", "Heathrow Airport - Terminal 1"],
	    ["HEATHROW TERMINAL 3", "Heathrow Airport - Terminal 3"],
	    ["HEATHROW TERMINAL 4", "Heathrow Airport - Terminal 4"],
	    ["HEATHROW TERMINAL 5", "Heathrow Airport - Terminal 5"]
	
        ]


	};


var AddressShortcuts = [AS_Airport];


I have another drop down list on the same form called DDvehAttr

Drop Down 2 - DDvehAttr
Code:
<select id="DDvehAttr" class="FormField" onchange="DDvehAttrChanged(this)" >
              <option value="-2">Please Select . . .</option>
<%
              for (i=0; i < vehAttr.length; i++)
              {%>
              <option value="<% = i %>"><% = vehAttr[i] %></option>
              <%}
%>
            </select>

This drop down is populated from another file called global.inc.

Code:
Session("ListAttributes")                = [

			["Standard Saloon", 	["01. Saloon [SAL]"]],
			["Executive Saloon", 	["07. Executive Saloon [EXEC-SAL]"]],
			["Estate Vehicle", 	["02. Estate [EST]"]],
			["People Carrier", 	["03. 5 Seater [5ST]"]],
			["8 Seater Vehicle", 	["06. 8 Seater [8ST]"]],		
						
					   ];


What I am trying to do is change the values of Drop Down 2 based on the value of Drop Down 1. Drop Down 1 has an onchange event called DDPaddrTypeChanged

DDPaddrTypeChanged
Code:
function DDPaddrTypeChanged(control)
{
    DDPaddrTypeIndex = control.selectedIndex;
    if (HandlePickup) HandlePickup.destruct();
    HandlePickup     = null;
    Validate(1, false);
    $("PAinput").hide();
    $("PAshow").innerHTML = "";
    defPickupIndex   = -1;
 
    SetPaddrType(true);
}


Is there a way to add a feature to the function above, in pseudo code i would want to achieve the following:

Code:
IF Drop Down 1 value = "Heathrow Airport" THEN
Drop Down 2 values are:
			["Standard Saloon",  [ "01. Saloon [SAL]", "30. Meet & Greet [M&G]" ]],
			["Executive Saloon",  [ "07. Executive Saloon [EXEC-SAL]", "30. Meet & Greet [M&G]" ]],
			["Estate Vehicle",  [ "02. Estate [EST]", "30. Meet & Greet [M&G]" ]],
			["People Carrier",  [ "03. 5 Seater [5ST]", "30. Meet & Greet [M&G]" ]],
			["8 Seater Vehicle",  [ "06. 8 Seater [8ST]", "30. Meet & Greet [M&G]" ]]

ELSE
Drop Down 2 values are:
			["Standard Saloon", 	["01. Saloon [SAL]"]],
			["Executive Saloon", 	["07. Executive Saloon [EXEC-SAL]"]],
			["Estate Vehicle", 	["02. Estate [EST]"]],
			["People Carrier", 	["03. 5 Seater [5ST]"]],
			["8 Seater Vehicle", 	["06. 8 Seater [8ST]"]],

END IF



CONCLUSION
It has taken me 1 hour to prepare this post. I am very serious about getting this done ASAP. If nobody can see an obvious solution (code example for me to test) then can somebody PLEASE help me understand the logic of how this was built (off the shelf product) and how I can acheive this feature. If you need any additional code I CAN SUPPLY IT

Thanks
 
Glad to have help. Hope you can find the issue, and its easy to fix.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
ok, i have made some good progress. it is almost working.

i have resolved the drop down menu not changing and also fixed the value issue by reducing the start counter from 0 to -1. Here is the new code that is working:

Code:
function Repopulate_DD2(){
var dd2=document.getElementById('DDvehAttr');
dd2.options.length=-1;
//run a loop to populate drop down
for(var i=-0; i<=AS_Airport.dd2options.length-1;i++){
var optn = document.createElement("OPTION");
optn.text = AS_Airport.dd2options[i][0];
optn.value = i;
dd2.options.add(optn);

}

}


function Repopulate_DD3(){
var dd3=document.getElementById('DDvehAttr');
dd3.options.length=-1;
//run a loop to populate drop down
for(var i=0; i<=AH_Hotel.dd3options.length-1;i++){
var optn = document.createElement("OPTION");
optn.text = AH_Hotel.dd3options[i][0];
optn.value = i;
dd3.options.add(optn);

}

}

the only problem i am facing now is that in the original 'off the shelf' product, by using the following:

Code:
["Standard Saloon (4 passengers, 2 suitcases, 2 carry ons)",  [ "01. Saloon [SAL]", "30. Meet & Greet [M&G]" ]],

it would tell my database to take the Saloon Charge and also the Meet & Greet Charge. It should automatically add £6.00 to the fare. At the moment this second vale within the option 30. Meet & Greet [M&G]" is not being sent to the database and not being charged.

i am quite confused by this because the actual lines of code have not changed at all?

if you have any idea why then please do let me know. im looking into it now but it's very confusing.

thanks
 
ok, i have seen the problem and am quite sure it is down to a basic formatting issue. perhaps i am missing a [ or '

basically when the form loads, these values when used in the drop down menu retrieve both charges from my database:
Charge 1 - 01. Saloon [SAL] - £42.00
Charge 2 - 30. Meet & Greet [M&G] - £6.00

the result is £48.00 (correct!)

Code:
Session("ListAttributes")                = [

	    ["AIRPORTStandard Saloon (4 passengers, 2 suitcases, 2 carry ons)",  [ "01. Saloon [SAL]", "30. Meet & Greet [M&G]" ]],
            ["AIRPORTExecutive Saloon (4 passengers, 2 suitcases, 2 carry ons)",  [ "07. Executive Saloon [EXEC-SAL]", "30. Meet & Greet [M&G]" ]],
            ["AIRPORTEstate Vehicle (4 passengers, 4 suitcases, 4 carry ons)",  [ "02. Estate [EST]", "30. Meet & Greet [M&G]" ]],
            ["AIRPORTPeople Carrier (5 passengers, 5 suitcases, 5 carry ons)",  [ "03. 5 Seater [5ST]", "30. Meet & Greet [M&G]" ]],
            ["AIRPORT8 Seater Vehicle (8 passengers, 8 suitcases, 8 carry ons)",  [ "06. 8 Seater [8ST]", "30. Meet & Greet [M&G]" ]]			];


however, when the same values are used in the 'new values' like so:

Code:
var AS_Airport =
    {
    group :
        "Heathrow Airport",

    premise:
        "Flight Number (eg VS401 Dubai)",

    shortcuts :
        [           

        ["HEATHROW TERMINAL 1", "Heathrow Airport - Terminal 1"],
        ["HEATHROW TERMINAL 3", "Heathrow Airport - Terminal 3"],
        ["HEATHROW TERMINAL 4", "Heathrow Airport - Terminal 4"],
        ["HEATHROW TERMINAL 5", "Heathrow Airport - Terminal 5"]
    
        ], 
    dd2options : //Add your heathrow specific options to your heathrow object, or to another object
        [b][
            
	    ["Please Select . . .",     [" "]],
            ["AIRPORTStandard Saloon (4 passengers, 2 suitcases, 2 carry ons)",  [ "01. Saloon [SAL]", "30. Meet & Greet [M&G]" ]],
            ["AIRPORTExecutive Saloon (4 passengers, 2 suitcases, 2 carry ons)",  [ "07. Executive Saloon [EXEC-SAL]", "30. Meet & Greet [M&G]" ]],
            ["AIRPORTEstate Vehicle (4 passengers, 4 suitcases, 4 carry ons)",  [ "02. Estate [EST]", "30. Meet & Greet [M&G]" ]],
            ["AIRPORTPeople Carrier (5 passengers, 5 suitcases, 5 carry ons)",  [ "03. 5 Seater [5ST]", "30. Meet & Greet [M&G]" ]],
            ["AIRPORT8 Seater Vehicle (8 passengers, 8 suitcases, 8 carry ons)",  [ "06. 8 Seater [8ST]", "30. Meet & Greet [M&G]" ]][/b]
     
    
            ]
     
    };

...only the first part of the charge is sent to the database (i.e the type of vehicle). the Meet & Greet charge is ignored and not sent. Can you see why this wouldnt be sent when they both look the same??
 
also my plan to fix the value jumping ahead

ie changing
dd2.options.length=0

to
dd2.options.length=-1

doesn't work, it fails to update the second drop down..

oh no
:(
 
it fixes the values but it says Invalid argument for chracter '1'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top