Home Javascript JavaScript click method
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

JavaScript click method

Advertisement
In the html page we can select the check box either by clicking on the checkbox option while selecting any option or we can call the JavaScript method click() on the checkbox object.

JavaScript click method

     

In the html page we can select the check box either by clicking on the checkbox option while selecting any option or we can call the JavaScript method click() on the checkbox object. In this example we have developed an example which shows how one can select the checkbox by using the method click.

Syntax:

 CheckBoxObject.click();

Description of code:

Here in this example html code we have create three check boxes and three buttons. In these three checkboxes we have called the three different functions selectFirst(), selectSecond(), selectThird().All these three methods calls the click method with the checkbox objects.

Here is the full example source code of clickExample.html as follows:

<html>
<body>
<script language="JavaScript">
  function selectFirst() {
   checkbox1.focus(); 
   checkbox1.click();
  }
  function selectSecond() {
   checkbox2.focus(); 
   checkbox2.click();
  }
  function selectThird() {
   checkbox3.focus(); 
   checkbox3.click();
  }
</script>
   <p>&nbsp;</p>
   <p align="center">&nbsp;</p>
   <div style="background: #cf2255; width:'100%';" align="center">
   <font color="#ffffcc" size="12pt"><b>Click Example</b></font></div>
   <center>
   <p align="left">
   <input type="checkbox" id="checkbox1" value="Checkbox1">
   <button onclick="selectFirst();">Click first checkbox</button>
  </p>
  <p align="left">
  <input type="checkbox" id="checkbox2" value="Checkbox1">
  <button onclick="selectSecond();">Click second checkbox</button>
  </p>

  <p align="left">
  <input type="checkbox" id="checkbox3" value="Checkbox3">
  <button onclick="selectThird();">Click third checkbox</button>
  </p>
  </body>
</html>

Output :

Download Source Code

     

Advertisements

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: January 29, 2009

Related Tutorials

Ask Questions?    Discuss: JavaScript click method   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com