Jump to content

how to hide/show label along with drop down menu?


matt121400

Recommended Posts

ok i am able to hide/show the menu based on a radio button but how would i also be able to hide/show the label that corresponds to the menu also?

I have included the code i am currently using

thanks!

 

<input type="radio" input onclick="javascript:document.getElementById('relocate').style.visibility='visible'" name="relocate2" class="fieldradio" onclick="relocate2Change(this);" />
    yes
    <input type="radio" name="relocate2"   class="fieldradio"   onclick="relocate2Change(this);" />
    No    </span>  </p>
    
<LABEL for="relocate">Relocation: </LABEL><select name="relocate" id="relocate" style="visibility:hidden"/>


  <option value="No" checked='checked'>No Relocation</option>
    <option value=N"Alabama">Alabama</option>
  <option value="Alaska">Alaska</option>
  <option value="Arizona">Arizona</option>
  <option value="Arkansas">Arkansas</option>
  <option value="California">California</option>
  <option value="Colorado">Colorado</option>
    </select>

You can make two calls within an even trigger like so:

onclick="function1();function2()"

 

But you shouldn't do that in this case. It is better to separate the javascript from the presentation. Also, you can make it much easier by just putting a span around the label and the select list and just changing the visibility of the span:

 

<html>
<head>

<script type="text/javascript">
  function showRelo(visiState)
  {
    document.getElementById('reloSpan').style.visibility = visiState;
  }
</script>

</head>
<body>

<input type="radio" name="relocate2" class="fieldradio" onclick="showRelo('visible');" />Yes
<input type="radio" name="relocate2" class="fieldradio" onclick="showRelo('hidden');" checked="checked" />No
<br />
<span id="reloSpan" style="visibility:hidden">    
<label for="relocate">Relocation:</label>
<select name="relocate" id="relocate">
  <option value="No" checked='checked'>No Relocation</option>
  <option value=N"Alabama">Alabama</option>
  <option value="Alaska">Alaska</option>
  <option value="Arizona">Arizona</option>
  <option value="Arkansas">Arkansas</option>
  <option value="California">California</option>
  <option value="Colorado">Colorado</option>
</select>
</span>

</body> 
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.