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.
We just installed our new forum/community .. please check it out: Killersites Community. THIS FORUM IS NOW AN ARCHIVE. Old user accounts and posts have been transferred to the new forum.
I've started a new topic on the move here TALK ABOUT NEW FORUM
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.
Copyright © 1996-2010 KillerSites.com | 