Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Javascript Javascriptexamples JavaScript Checkbox getElementById

Related Tutorials


 
 

Share on Google+Share on Google+

JavaScript Checkbox getElementById

Advertisement
This page discusses - JavaScript Checkbox getElementById

JavaScript Checkbox getElementById()

        

In this section, we are going to use the method getElementById() for checkbox in JavaScript.

In the given example we are going to show an image on clicking the checkbox. This is done by using the JavaScript method getElementById() that is used to get the value of the particular element by their id. Here, we have defined an image and created a checkbox that calls the function showImage(). This function allows to display an image if you clicked the checkbox.

document.getElementById("image").style.visibility = 'visible'- This makes the image visible.

document.getElementById("image").style.visibility = 'hidden'- This makes the image invisible. 

Here is the code:

<html>
<h2>Use of getElementById()</h2>
<script>
function showImage(){
if(document.getElementById('check').checked==true){
document.getElementById("image").style.visibility = 'visible'; 
}
else if(document.getElementById('check').checked==false){
document.getElementById("image").style.visibility = 'hidden'; 
}
}
</script>
<body onload="showImage()">
<input type="checkbox" id="check" onclick="showImage()" />
Show Image
<form>
<img id="image" src="node.jpg">
<form>
</body>
</html>

Output will be displayed as:

As you click the checkbox, the image get displayed:

Download Source Code:

        

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 18, 2011

Related Tutorials

Discuss: JavaScript Checkbox getElementById  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
Akanksha Dhingra
November 25, 2011
Javascript

if i want to pass the parameters from one jsp page to another jsp page of the ratings then what will be the code for this. example: interior rating of the room - 1 2 3 4 5 if the person clicks one of the rating then how would we paas it to another page
DMCA.com