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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.