Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript_howto thread: Hide Layers Based on SELECT Value


Message #1 by "Eric" <eric@d...> on Mon, 1 Jul 2002 16:01:15 -0400
Eric,
Several suggestions:
1. as previous post says, javascript is case-sensitive so use "if" not "If"
2. you are missing a right curly bracket } to match the first if
3. if you change your coding style to use paired indentation you
   will be much more likely to see problems like (2), e.g.
function show_hide_PriceMod()
{
  if(document.style_mgmt.price_mod.value == 1)
  {
    if(IE)
    {
      document.all.style_price.style.visibility = "visible";
    }
    if(NN)
    {
      document.layers.style_price.visibility = "visible";
    }
  }
}
4. I usually use style='display: none' to hide DIVs
   and style='display:' to show them. In your case this would
   be:
      document.all.style_price.style.display="";  //show it
   or
      document.all.style_price.style.display="none";  //hide it


>---original post-------
> Afternoon all,

I am a total non-js programmer so please bear with what is most likely a
totally amateur question.  I am building a form where based on the
selection made via a SELECT tag, I would like to dynamically hide/show
various text boxes on the form. I have created the tag and the necessary
<DIV> layers.  No matter what I do I am getting errors where I am
missing a ")" or a ";".  Any help would be very much appreciated.

NN = (document.layers) ? true : false;
IE = (document.all)    ? true : false;

function show_hide_PriceMod(){
  If (document.style_mgmt.price_mod.value == 1){
    If (IE){
      document.all.style_price.style.visibility = "visible";
	}
    If (NN){
      document.layers.style_price.visibility = "visible";
	}
}

The Form name is: style_mgmt

HTML Calling the function:
"<SELECT NAME = price_mod CLASS = adm_body SIZE = 1 OnChange = " &
vbQuote & "show_hide_PriceMod()" & vbQuote & ">" & _

DIV Tag:
"<DIV ID = style_mgmt  STYLE = " & vbQuote & "VISIBILITY:hidden;
POSITION:relative; TOP:0; LEFT:0" & vbQuote & ">" & _
...


Regards,
Eric


  Return to Index