Topic: i need to show a form only when a checkbox is ticked
i need to show a form only when a checkbox is ticked.
Im guessing i need to use jquery to do this.
Anyone know of a tutorial which explains this - or even better your advice.
You are not logged in. Please login or register.
Hi, I just released our new video tutorial course on Flash CS4.
Stefan
Killersites.com Web Design Forums » HTML/XHTML » i need to show a form only when a checkbox is ticked
i need to show a form only when a checkbox is ticked.
Im guessing i need to use jquery to do this.
Anyone know of a tutorial which explains this - or even better your advice.
you CAN use jQuery indeed, but you dont NEED to use jQuery, just normal Javascript is fine.
the normal way:
say you have a checkbox, and the form you want to hide/show is contained inside a div with an id="myDiv"
<input type="checkbox" value="myValue" name="myName" onchange="showHide(this)">
<div id="myDiv>
<form name="myForm">
.....
</form>
</div>then you need a function called showHide that takes an element/object as a paramer -> (this)
<script type="text/javascript">
function showHide(obj)
{
if(obj.checked){
// if checkbox is checked then show div with id "myDiv"
document.getElementById("myDiv").style.display = "block";
}
else{
// otherwise hide div with id "myDiv"
document.getElementById("myDiv").style.display = "none";
}
}
</script>I posted some of the code you would need to use to do this with jQuery. BeeDev is right though -- this could be simply done with regular javascript.
Seemed a bit of overkill to include 55kb javascript lib (jQuery) just to hide/show a layer.
Posts [ 4 ] - Views [ 487 ]
Copyright © 1996-2009 Killersites.com
[ Generated in 0.116 seconds, 9 queries executed ]