Jump to content

Show / Hide Text


mme

Recommended Posts

Hi

 

I am trying to make it when using grouped radio buttons the user either presses yes or no.

When Yes is pressed it shows the content in div id "dn2" and when No is pressed it hides div id "dn2" and shows "dn" instead. But when the page is loaded neither div id "dn" or "dn2" are to be shown.

 

<body>
<script type="text/javascript">
if( document.getElementById ) {
getElemById = function( id ) {
return document.getElementById( id );
}
} else if( document.all ) {
getElemById = function( id ) {
return document.all[ id ];
}
} else if( document.layers ) {
getElemById = function( id ) {
return document.layers[ id ];
}
}
function showhide( el, id) {
if ( el && el.style ) {
getElemById( id ).style.display = (el.checked)? 'none' : '';
}
}
</script>
<label>
  <input type="radio" name="q1" value="radio" id="q1_0" onclick="showhide(this, 'dn2');" />
Yes</label>
   
  <label>
  <input type="radio" name="q1" value="radio" id="q1_1" onclick="showhide(this, 'dn');" />
No</label>
  <br>
  
  <div id="dn" class="noshow">Text 1</div>
  <div id="dn2" class="noshow">Text 2</div>
</body>

 

Thanks  :)

Link to comment
https://forums.phpfreaks.com/topic/102266-show-hide-text/
Share on other sites

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.