FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

simplest way to make hidden divs visible via onlick and java

 


velcrobandits
can someone please show me how to do this? i dont know javascript, and I can't understand the code samples i see online. what is the easiest way (least amount of code) to make an <a> tag make a div visible? thanks.
Mosquito.Tyler
This is the simplest way I know, there is only one function of JavaScript. If you don't know enough JavaScript to do something, perhaps you should try to learn JavaScript, no?

http://w3schools.com/js/default.asp is a great place to start.

Happy Learning!
welshsteve
You can use the GetElementByID feature of Javascript. Try the below.
Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<title>Show/Hide</title>
<style type="text/css">
<!--
.hide {
    display:none;
    margin-top: 20px;
    margin-left:10px;
}
-->
</style>   
<script type="text/javascript">
<!--
window.onload=function() {

   inp=document.getElementsByTagName('input');
for(c=0;c<inp.length;c++) {
   inp[c].onclick=function() {

for(c=0;c<inp.length;c++) {
   document.getElementById('div'+(c+1)).className='hide';
 }
   num=this.id.split('rad')[1]
   document.getElementById('div'+num).className='';
   }
  }
 }
//-->
</script>
   
</head>
<body>

<div>
<input type="radio" id="rad1"/><label for="rad1"> Div 1</label>
<input type="radio" id="rad2"/><label for="rad2"> Div 2</label>
<input type="radio" id="rad3"/><label for="rad3"> Div 3</label>
<input type="radio" id="rad4"/><label for="rad4"> Div 4</label>
</div>
<div id="div1" class="hide">
   This is DIV 1
</div>
<div id="div2" class="hide">
   This is DIV 2
</div>
<div id="div3" class="hide">
   This is DIV 3
</div>
<div id="div4" class="hide">
   This is DIV 4
</div>

</body>
</html>
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.