Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8212433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:45:22+00:00 2026-06-07T10:45:22+00:00

I have 4 checkbox on top a page and there are 4 corresponding div

  • 0

I have 4 checkbox on top a page and there are 4 corresponding div elements. I need to display the div if the corresponding checkbox is selected and the other div’s to be hidden. I had achieved this but not able to position them properly.

For example, If I select the 3rd checkbox, the div corresponding to the 3rd checkbox should be displayed at the top. Then If I select the 1st checkbox, the div corresponding to the 1st checkbox should be diplayed first followed by the div corresponding to the 3rd checkbox. Then if I select the 2nd checkbox, the 2nd div should be displayed between the 1st and 3rd div.

The hide functionality works fine. But with respect to position of the div, the 3rd div is getting displayed at the 3rd position (meaning that there is a space at the top of the page which corresponds to the first two div’s). Below is the html file and the java script which I use:

<html> 
<head> 
<title>Checkbox Event Handler</title> 

<script type="text/javascript"> 

function toggle(chkbox, group) { 
    var visSetting = (chkbox.checked) ? "visible" : "hidden"; 
    document.getElementById(group).style.visibility = visSetting; 
 document.getElementById(group).style.position = absolute;
} 

function hideLayer() {
document.getElementById('myGroup1').style.visibility = 'hidden';
document.getElementById('myGroup2').style.visibility = 'hidden';
document.getElementById('myGroup3').style.visibility = 'hidden';
document.getElementById('myGroup4').style.visibility = 'hidden';
}

</script> 
</head> 
<body onload="hideLayer();"> 
<form> 
<input type="checkbox" name="section1" onclick="toggle(this, 'myGroup1')" />Section1
<input type="checkbox" name="section2" onclick="toggle(this, 'myGroup2')" />Section2
<input type="checkbox" name="section2" onclick="toggle(this, 'myGroup3')" />Section3
<input type="checkbox" name="section2" onclick="toggle(this, 'myGroup4')" />Section4


<div id="myGroup1" >
<table >

<tr><td>ID </td><td><input type="text" name ="tid" id="tid" size="20"></input></td></tr>
<tr><td>Name </td><td><input type="text" name = "tname" id="tname" size="20"></td></tr>
<tr><td>Height </td><td><input type="text" name = "theight" id="theight" size="20"></td></tr>
<tr><td>Location </td><td><input type="text" name = "tloc" id="tloc" size="20"></td></tr>
</table>
</div>
<div id="myGroup2" >
<table>
<tr><td><input type="button" name ="B1" id="B1" value="SomeName" ></td>
<td><input type="button" name ="B2" id="B2" value="Retrieve" >
<input type="button" name ="B3" id="B3" value="Retrieve All" >
<input type="button" name ="B4" id="B4" value="Load Data" >
</td></tr>

</table>
</div>

<div id="myGroup3">
  <table >

<tr><td>City </td><td><input type="text" name = "tcity" id="tcity" size="20"></td></tr>
<tr><td>State </td><td><input type="text" name = "tstate" id="tstate" size="20"></td></tr>
<tr><td>Country </td><td><input type="text" name = "tcountry" id="tcountry" size="20"></td></tr>
</table>
</div>
<div id="myGroup4">
<table>
<tr><td><input type="button" name = "B4" id="B4" value="SomeButton" ></td>
<td><input type="button" name ="B5" id="B5" value="Store" >
<input type="button" name ="B6" id="B6" value="Clear All" >
<input type="submit" name ="B7" id="B7" value="Submit"></td></tr>

</table>
</div>
</form> 
</body> 
</html> 

I use the “document.getElementById(group).style.position = absolute” to set the position but not sure of how to use this. Please help…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T10:45:25+00:00Added an answer on June 7, 2026 at 10:45 am

    visibility:hidden make the div not appear but still exist in the layout.

    With display:none The element will be hidden, and the page will be displayed as if the element is not there

    EDIT

    Here’s how I got it to work JSFiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have checkbox list printed in one column, but i need it to print
I have several places on the page where there is text Add This text
I have this code that will check the top level checkbox if the checkboxes
I have a web page and in it I have a checkbox at the
I have checkBox and Spinner . If the checkbox is checked, then spinner should
I have a checkbox with an id of activelist I tried the following but
I have a checkbox in the Android layout file. When the checkbox is clicked
I have a checkbox that I do not want the user to have direct
I have a CheckBox in my application that is using the TriState mode. The
I have added checkbox selection model to grid panel. It works fine in IE8

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.