p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

proasp_codeclinic thread: hidden/visible tags


Message #1 by "Paloma Bernardos" <p.bernardos@c...> on Mon, 19 Feb 2001 12:39:39
give each div the same name (e.g. divMercado), then they will form an array
of divs

and you can do this

<script language="VbScript">
   sub LstMercado_Onchange
	
	set aDivs = document.all.divMercado
	
	'hide all first
	for i= 0 to aDivs.length-1
	     adivs(i).classname ="Oculto"
	next

	'now show selected
	i = 	LstMercado.selectedIndex
	aDivs(i).classname ="visible"
	
   end sub
</script>

although rather that looping through and hiding each one, it would actually
be more efficient to store a pointer to the currently displayed div and only
hide that one, as the others should be hidden anyway

e.g.

<script language="VbScript">
   dim oDiv

   sub LstMercado_Onchange
	
	set aDivs = document.all.divMercado
	
	'hide currently selected
	if oDiv <> nothing then oDiv.classname ="Oculto"
	
	'now show selected
	i = 	LstMercado.selectedIndex
	oDiv = aDivs(i)
	oDiv.classname ="visible"
	
   end sub
</script>

-----Original Message-----
From: Paloma Bernardos [mailto:p.bernardos@c...]
Sent: Monday, February 19, 2001 9:02 PM
To: Code Clinic
Subject: hidden/visible tags


I have five div, and a select with five elements.  By default, divs are 
hidden.

When I choose an element in the select, I have the respective div visible 
and the others hidden. 

Choose what I Choose, all divs show.

<script language="VbScript">
   sub LstMercado_Onchange

	vp=mid(form1.lstmercado.value,1,3)

	set aDivs = document.body.all.tags("DIV")

	for i= 0 to aDivs.length-1
	     if adivs(i).id = vp then
		adivs(i).classname ="visible"
	     else
		adivs(i).classname ="Oculto"
	     end if
	next
   end sub
</script>

Thanks for your help.

________________________________________________________________________
Scottish Enterprise Network
http://www.scottish-enterprise.com



  Return to Index