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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Toggling 3 select boxes 1

Status
Not open for further replies.

TribeMan

Programmer
Nov 16, 2009
22
IL
I have 3 select boxes: selCountry, selCity and selSuburb.

If no selection is made in selCountry, then the remaining 2 select boxes should be inactive.
If selection is made in selCountry, then selCity should be active and selSuburb inactive.
If selection is made in selCountry and selCity, then selSuburb should also be active.

I tried the code below (for 2 select boxes), but how do I incorporate 3 select boxes?

Many thanks from the new kid on the block!

==========================
function toggleCountryCitySuburb(country_type){
if(! country_type) return;

var frm = country_type.form;
if(country_type.value == ""){
frm.selCity.disabled = true;
frm.selSuburb.disabled = true;
} else {
frm.selCity.disabled = false;
frm.selSuburb.disabled = true;
}
}
===============================
 
Hi

Please post the relevant HTML code too ( cut off decorations, redundant elements and shorten the [tt]option[/tt]s ).

Please post your code between [tt][ignore]
Code:
[/ignore][/tt] and [tt][ignore]
[/ignore][/tt] TGML tags.

Feherke.
 
Here's the relevent HTML code:
Code:
<select name="selCountry" id="selCountry">
  <option value="">--Select country--</option>
  <option value="0">All countries</option>
  <%=list_CountryOptions(forumAdd_Country)%>
</select>

<select name="selCity" id="selCity">
  <option value="">--Select city--</option>
  <option value="0">All cities</option>
  <%=list_CityOptions(forumAdd_City)%>
</select>

<select name="selSuburb" id="selSuburb">
  <%=list_SuburbOptions(forumAdd_Suburb)%>
</select>
 
Hi

Feherke said:
Please post the relevant [red]HTML[/red] code
No ASP, PHP, JSP and other server-side code, please. Those are not helping us to reproduce your script's running environment.

Where, when and how is that toggleCountryCitySuburb() function called ?


Feherke.
 
Hi

We certainly have some good examples in the older threads, maybe between the FAQs too. Anyway, I think I would write it like this :
JavaScript:
[b]function[/b] [COLOR=darkgoldenrod]tog[/color][teal]([/teal]what[teal],[/teal]next[teal])[/teal]
[teal]{[/teal]
  next[teal].[/teal]disabled[teal]=![/teal]what[teal].[/teal]selectedIndex
  [b]if[/b] [teal]([/teal]next[teal].[/teal]disabled[teal])[/teal] next[teal].[/teal]selectedIndex[teal]=[/teal][purple]0[/purple]
  [b]if[/b] [teal]([/teal]what[teal]==[/teal]refcountry[teal])[/teal] [COLOR=darkgoldenrod]tog[/color][teal]([/teal]next[teal],[/teal]refsuburb[teal])[/teal]
[teal]}[/teal]

window[teal].[/teal]onload[teal]=[/teal][b]function[/b][teal]()[/teal] [teal]{[/teal]
  refcountry[teal]=[/teal]document[teal].[/teal][COLOR=darkgoldenrod]getElementById[/color][teal]([/teal][green][i]'selCountry'[/i][/green][teal])[/teal]
  refcity[teal]=[/teal]document[teal].[/teal][COLOR=darkgoldenrod]getElementById[/color][teal]([/teal][green][i]'selCity'[/i][/green][teal])[/teal]
  refsuburb[teal]=[/teal]document[teal].[/teal][COLOR=darkgoldenrod]getElementById[/color][teal]([/teal][green][i]'selSuburb'[/i][/green][teal])[/teal]
  [COLOR=darkgoldenrod]tog[/color][teal]([/teal]refcountry[teal],[/teal]refcity[teal])[/teal]
[teal]}[/teal]
HTML:
[b]<select[/b] [maroon]name[/maroon][teal]=[/teal][green][i]"selCountry"[/i][/green] [maroon]id[/maroon][teal]=[/teal][green][i]"selCountry"[/i][/green] [maroon]onclick[/maroon][teal]=[/teal][green][i]"tog(this,refcity)"[/i][/green][b]>[/b]
  [b]<option[/b] [maroon]value[/maroon][teal]=[/teal][green][i]""[/i][/green][b]>[/b]--Select country--[b]</option>[/b]
  [b]<option[/b] [maroon]value[/maroon][teal]=[/teal][green][i]"0"[/i][/green][b]>[/b]All countries[b]</option>[/b]
[b]</select>[/b]

[b]<select[/b] [maroon]name[/maroon][teal]=[/teal][green][i]"selCity"[/i][/green] [maroon]id[/maroon][teal]=[/teal][green][i]"selCity"[/i][/green] [maroon]onclick[/maroon][teal]=[/teal][green][i]"tog(this,refsuburb)"[/i][/green][b]>[/b]
  [b]<option[/b] [maroon]value[/maroon][teal]=[/teal][green][i]""[/i][/green][b]>[/b]--Select city--[b]</option>[/b]
  [b]<option[/b] [maroon]value[/maroon][teal]=[/teal][green][i]"0"[/i][/green][b]>[/b]All cities[b]</option>[/b]
[b]</select>[/b]

[b]<select[/b] [maroon]name[/maroon][teal]=[/teal][green][i]"selSuburb"[/i][/green] [maroon]id[/maroon][teal]=[/teal][green][i]"selSuburb"[/i][/green][b]>[/b]
  [b]<option[/b] [maroon]value[/maroon][teal]=[/teal][green][i]""[/i][/green][b]>[/b]--Select suburb--[b]</option>[/b]
  [b]<option[/b] [maroon]value[/maroon][teal]=[/teal][green][i]"0"[/i][/green][b]>[/b]All suburbs[b]</option>[/b]
[b]</select>[/b]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top