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!

linked dropdowns

Status
Not open for further replies.

slowfish

Programmer
Aug 21, 2009
28
GB
Hi

I know this has been asked many times before but I can't seem to work out a way of doing the following...

First dropdown options are yes/no
Second dropdown options are yes/no

If yes selected from first dropdown, selected value of second dropdown is also "yes"

thanks
 
Thanks for that, but still having trouble.... any ideas?

function selectOption()
{
var selObj = document.ff.getElementById('selarchived');
if (document.ff.deceased.options[document.ff.deceased.selectedIndex].value == 'yes') {
selObj.document.ff.archived.options[document.ff.archived.selectedIndex].value = 'yes';
}

}
 
Hi

There you are changing the [tt]value[/tt] of the currently selected [tt]option[/tt]. Is like replacing this :
HTML:
[small][b]<select[/b] [maroon]name[/maroon][teal]=[/teal][green][i]"archived"[/i][/green][b]>[/b]
[b]<option[/b] [maroon]value[/maroon][teal]=[/teal][green][i]"yes"[/i][/green][b]>[/b]Yes[b]</option>[/b][/small]
[b]<option[/b] [maroon]value[/maroon][teal]=[/teal][green][i]"no"[/i][/green] [maroon]selected[/maroon][teal]=[/teal][green][i]"selected"[/i][/green][b]>[/b]No[b]</option>[/b]
[small][b]</select>[/b][/small]
with this :
HTML:
[small][b]<select[/b] [maroon]name[/maroon][teal]=[/teal][green][i]"archived"[/i][/green][b]>[/b]
[b]<option[/b] [maroon]value[/maroon][teal]=[/teal][green][i]"yes"[/i][/green][b]>[/b]Yes[b]</option>[/b][/small]
[b]<option[/b] [maroon]value[/maroon][teal]=[/teal][green][i]"[highlight]yes[/highlight]"[/i][/green] [maroon]selected[/maroon][teal]=[/teal][green][i]"selected"[/i][/green][b]>[/b]No[b]</option>[/b]
[small][b]</select>[/b][/small]
Given that you have the same two values in both [tt]select[/tt]s, I would manipulate only the [tt]selectedIndex[/tt] properties :
JavaScript:
[b]function[/b] [COLOR=darkgoldenrod]selectOption[/color][teal]()[/teal]
[teal]{[/teal]
  [b]if[/b] [teal]([/teal]document[teal].[/teal]ff[teal].[/teal]deceased[teal].[/teal]selectedIndex[teal]==[/teal][purple]0[/purple][teal])[/teal]
    document[teal].[/teal]ff[teal].[/teal]archived[teal].[/teal]selectedIndex[teal]=[/teal][purple]0[/purple][teal];[/teal]
[teal]}[/teal]


Feherke.
 
That's perfect... and very simple!
Many thanks Feherke
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top