Referecing the boolean value of a checkbox from a function

I am a javascript newbie. I am using Google Maps on my site, and add the following control:

<input type="checkbox" id="chkA" onClick="getOverlays()">

From my getOverlays function, I want to be able to use the IF statement (or case) to decide the incoming value from the checkbox, ie, if it is checked or not. That way I can run either of two scenarios.

How can I pass the checked value of the checkbox through to the function?

Who is Participating?
ZvonkoSystems architectCommented:
Or you extend your function call to this:
<input type="checkbox" id="chkA" onClick="getOverlays(this)">

Then your checkbox value acces can be done like this:


function getOverlays(theBox){
    // do this
  } else {
   // do that


Hi Craig,

To assign the boolean value of the checkbox to the variable 'bool,' place the following line within your function getOverlays() :

var bool = document.getElementById('chkA').checked;

Peace and joy.  mvan
Also, if you wanted to keep your function from having to deal with a checkbox object and just receive a boolean, you can pass directly from your input element:


function getOverlays(someBool)
    // Do whatever you want with the value stored in someBool


<input type="checkbox" id="chkA" onClick="getOverlays(this.checked)">
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.