Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening and closing a DIV tag from a text link.

Status
Not open for further replies.

murphyhg

Technical User
Mar 1, 2006
98
US
I want to be able turn the display on and off by clicking a text link. Can someone please help me with that?

Here is my code.

<script language="JavaScript" type="text/javascript">
if (document.getElementById(strId).style.display == 'none')
}
function checkForm(strId, show) {
document.getElementById(strId).style.display = (show) ? 'inline' : 'none';
}
}
</script>
<script language="JavaScript" type="text/javascript">
if (document.getElementById(strId).style.display != 'none')
}
function checkForm(strId, show) {
document.getElementById(strId).style.display = (show) ? 'none' : 'inline';
}
}
</script>
<style type="text/css">
<!--
#closeThis {
display:none;
font-weight:normal;
}
-->
</style>

<a href="##" onclick="checkForm('closeThis', !this.checked);">What was the severity level of occurances for the past 2 years?</a>

<div id="closeThis">Hello</div>
 
good god.

1) only need one "#" in your href.
2) add a "return false" to your onclick, after the semicolon.
3) get rid of the HTML comments inside your style tag.
4) there is no way that javascript would work... change to:

Code:
function checkForm(strId) {
    var d = document.getElementById(strId);
    d.style.display = (d.style.display == 'block') ? 'none' : 'block';
}

your function call should look like:

Code:
<a href="#" onclick="checkForm('closeThis'); return false;">What was the severity level of occurances for the past 2 years?</a>



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top