On Untick of a checkbox?

A

Advo

Is this Possible? ive got some code which works onclick and makes a div
visible.

onClick='document.getElementById("question11_comment").style.visibility
= "visible";'

Basically, either need a way to do on untick, or on second click. So
the first time they click the box it will make the div visible, and
then the 2nd time, it will make it hidden.

Any ideas please?
 
L

Lee

Advo said:
Is this Possible? ive got some code which works onclick and makes a div
visible.

onClick='document.getElementById("question11_comment").style.visibility
= "visible";'

Basically, either need a way to do on untick, or on second click. So
the first time they click the box it will make the div visible, and
then the 2nd time, it will make it hidden.

onclick="if(checked){//stuff}else{//otherstuff}"

Easier to think about if the onclick handler calls a function
that handles the logic.


--
 
M

Marc

Advo said:
Is this Possible? ive got some code which works onclick and makes a div
visible.

onClick='document.getElementById("question11_comment").style.visibility
= "visible";'

Basically, either need a way to do on untick, or on second click. So
the first time they click the box it will make the div visible, and
then the 2nd time, it will make it hidden.

Any ideas please?

a sample:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css"> <!--
..show{visibility: visible}
..hide{visibility: hidden}
--></style>
<script language="javascript" type="text/javascript">
//<![CDATA[
function showHidediv(strDivId, boolshowhide){
var styleSwitch;
if(boolshowhide) styleSwitch = "show";
else styleSwitch = "hide";
document.getElementById(strDivId).className = styleSwitch;
}
//]]>
</script>
</head>
<body>

<input type="checkbox" id="checkbox1" name="checkbox1"
onclick="showHidediv('thediv', this.checked)">
<div id="thediv" class="hide">abcdefg</div>

</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,436
Messages
2,571,696
Members
48,796
Latest member
Greg L.
Top