SQL PHP HTML ASP JavaScript articles and free scripts to download
 
 

Showing & hiding div layers on button clicks

We can control a layer by connecting it to buttons. We can display or hide the layer by clicking the buttons. To create and manage a layer we will use div tags. By using style property of the page we can control the layer.


We will use one on page style sheet for our div tag by defining its layout properties. We will keep this style definition inside our head tags. For more details on Style property visit our CSS section.


We will use one JavaScript function to manage the property of the div tag identified by its id.


Here is a the demo



Message Box


Here is the code

<html>
<head>
<title>(Type a title for your page here)</title>
<style type="text/css">
div {
position: absolute;
left: 100px;
top: 200px;
background-color: #f1f1f1;
width: 180px;
padding: 10px;
color: black;
border: #0000cc 2px dashed;
display: none;
}
</style>

<script language="JavaScript">
function setVisibility(id, visibility) {
document.getElementById(id).style.display = visibility;
}
</script>

</head>
<body >

<input type=button name=type value='Show Layer' onclick="setVisibility('sub3', 'inline');";><input type=button name=type value='Hide Layer' onclick="setVisibility('sub3', 'none');";>

<div id="sub3">Message Box</div>

</body>
</html>
Further readings
Hide and displaying layers through buttons
Hide and displaying layers through radio buttons
OnClick event of period button
Default value by using OnFocus event of a text box
Showing help text by using onfocus and onBlur event triggers
Text box click event removing data
Text box onBlur click event changing case
Selecting all the data of inside textarea by clicking
Counting the characters dynamically inside a textarea and setting a limit
Copying a set of textbox entered data to another area of a form
Copying data along with drop down list box selection inside a form
Managing browser status bar message onMouseOver & onMouseOut events of a link
OnMouseOver image changing over a link
 
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.

Scripts
PHP
JavaScript
JavaScript Tutorials
Popular Tutorials
Drop down list
Timer function
JavaScript Tutorials
String
Array
Date & Time
Form Validation
Event Handling
Math Functions
Loops & structure
JavaScript Forum
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.