JavaScript Checkbox getElementById

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:

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

Output will be displayed as:

As you click the checkbox, the image get displayed:

Download Source Code:



Share on Google+Share on Google+

JavaScript Checkbox getElementById

Posted on: April 18, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: JavaScript Checkbox getElementById  

Post your Comment

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

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