2

Imagine I have an input like so:

<input id="submitCheckbox" type="checkbox" name="recieveEmails">

And some form of submit button, say;

<button id="submit" type="button" onclick="submit()"></button>

And Javascript like so:

function submit() {
    var newVar = document.getElementById("submitCheckbox");
}

And by using something like this, newVar would be equal to True or False depending on the status of the checkbox when the submit button is pressed?

PS. The Javascript example I provided is theoretical. Please don't rip into me because it "doesn't work"

1 Answers1

1

Use this document.getElementById("submitCheckbox").checked instead of document.getElementById("submitCheckbox") as shown here:

function submit() {
    var newVar = document.getElementById("submitCheckbox").checked;
    console.log(newVar);
}
<input id="submitCheckbox" type="checkbox" name="recieveEmails">
<br>
<button id="submit" type="button" onclick="submit()">Click</button>
Manish Joy
  • 476
  • 3
  • 17