Home Javascript JavaScript click method



JavaScript click method
Posted on: January 29, 2009 at 12:00 AM
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

     

Related Tags for JavaScript click method:
javajavascripthtmlcselectscriptobjectcheckboxiomethodippageclickclicheckcallboxwhileoptioneilitcanliinmlcalasmcajclallagemeobjsanykhtmllvascrssriripthaveitherkbjeono


More Tutorials from this section

Ask Questions?    Discuss: JavaScript click method   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.