Posted by: Amit Nazare on: July 16, 2009
Here is another tutorial for JavaScript. How to show/hide your div block with check box.
Its very easy and simple to understand. Just copy the below code and try.
JavaScript :
<script type=”text/javascript”>
function showMe (ids, box) {
var vis = (box.checked) ? “block” : “none”;
document.getElementById(ids).style.display = vis;
}
</script>
Here the above JavaScript code will check whether the checkbox is checked or not. If it is checked then it will return true and the block of code will be displayed. Else the block of code will be hidden(display:none)
Down below is the HTML code which will show you how to call the JavaScript function.
HTML Code :
<input type=”checkbox” name=”vendors” onclick=”showMe(‘viewVendors’, this)” /> View Vendors
<div style=”display:none;” id=”viewVendors”>
Block of code goes here
</div>
Try this code and get me your feedbacks, if any errorsor if it is not working let me know.
August 10, 2009 at 9:43 pm
Great! Didn’t work at first because I copied and pasted the above code directly into my code, but after changing the fancy “curly” quotes to straight quotes it worked like a charm. Thank you!
August 11, 2009 at 9:53 am
oh cool…