Corwin
07-17-2008, 04:09 PM
hello,
ive been looking for ways to make expandeable and contracteable text in my html code. i figured simple solution that does almost what i want it to, with one exception. i cannot figure out how to modify it to fit this exception.
here is the original code and a test page with it on it:
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
function toggleBox(id)
{
if (document.getElementById(id).style.display == "")
{
show = "none";
}
else
{
show = "";
}
document.getElementById(id).style.display = show;
}
</script>
</head>
<body>
<table><tr><td>
<a href="javascript:toggleBox(1)">Test1 </a></td><td><div id="1" style="display:none">Answer1 </div></td></tr>
<tr><td>
<a href="javascript:toggleBox(2)">Test2 </a></td><td><div id="2" style="display:none">Answer2 </div></td></tr>
<tr><td>
<a href="javascript:toggleBox(3)">Test3 </a></td><td><div id="3" style="display:none">Answer3 </div></td></tr>
<tr><td>
<a href="javascript:toggleBox(4)">Test4 </a></td><td><div id="4" style="display:none">Answer4 </div></td></tr>
</table>
</body>
</html>
http://webdev.wpcarey.asu.edu/tools/online_MBA_Dashboard/test.html
now, as you can see the test expands and contracts great, but what i would like to do is, if one is expanded and i go to expand another one i want that first oen to contract, so basically only *one* of them is ever extended at one time.
ive tried adding this line thinking ti would work, bu it didnt:
document.getelementbytagname(div).style.display == "";
i am not well versed in javascript, just getting into it recently, so any help with what i am doing wrong is greatly appreciated
thanks
-Corwin
ive been looking for ways to make expandeable and contracteable text in my html code. i figured simple solution that does almost what i want it to, with one exception. i cannot figure out how to modify it to fit this exception.
here is the original code and a test page with it on it:
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
function toggleBox(id)
{
if (document.getElementById(id).style.display == "")
{
show = "none";
}
else
{
show = "";
}
document.getElementById(id).style.display = show;
}
</script>
</head>
<body>
<table><tr><td>
<a href="javascript:toggleBox(1)">Test1 </a></td><td><div id="1" style="display:none">Answer1 </div></td></tr>
<tr><td>
<a href="javascript:toggleBox(2)">Test2 </a></td><td><div id="2" style="display:none">Answer2 </div></td></tr>
<tr><td>
<a href="javascript:toggleBox(3)">Test3 </a></td><td><div id="3" style="display:none">Answer3 </div></td></tr>
<tr><td>
<a href="javascript:toggleBox(4)">Test4 </a></td><td><div id="4" style="display:none">Answer4 </div></td></tr>
</table>
</body>
</html>
http://webdev.wpcarey.asu.edu/tools/online_MBA_Dashboard/test.html
now, as you can see the test expands and contracts great, but what i would like to do is, if one is expanded and i go to expand another one i want that first oen to contract, so basically only *one* of them is ever extended at one time.
ive tried adding this line thinking ti would work, bu it didnt:
document.getelementbytagname(div).style.display == "";
i am not well versed in javascript, just getting into it recently, so any help with what i am doing wrong is greatly appreciated
thanks
-Corwin