By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,567 Members | 1,554 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,567 IT Pros & Developers. It's quick & easy.

How do I indicate that a checkbox should be checked?

100+
P: 110
I have a form named "FrontPage_Form2" and a checkbox named "checkboxPowerUnit"; and, I want to programmatically change whether or not it is checked by default based on a selection made in a selection box. I have tried:

Expand|Select|Wrap|Line Numbers
  1. document.FrontPage_Form2.checkboxPowerUnit.checked=true;
  2. document.all.checkboxPowerUnit.checked=true;
  3. document.form[0].checkboxPowerUnit.checked=true;
  4. document.form[0].checkboxPowerUnit[0].checked=true;
  5. document.FrontPage_Form2].checkboxPowerUnit[0].checked=true;
and every one results in an error saying "document.whatever" is null or not an object. Can anyone tell me how to indicate that this checkbox should be checked or unchecked?
Nov 3 '09 #1
Share this Question
Share on Google+
4 Replies


Plater
Expert 5K+
P: 7,872
Assign it an id and then use document.getElementById(idstring)
Nov 3 '09 #2

100+
P: 110
it has an id. the id and the name are the same.
Nov 3 '09 #3

100+
P: 110
Expand|Select|Wrap|Line Numbers
  1. document.getElementById('checkboxPowerUnit').checked=true;
  2. document.getElementById('checkboxPowerUnit').value="YES";
also do not work
Nov 3 '09 #4

Plater
Expert 5K+
P: 7,872
Are you perhaps running this script before the page has loaded?
if document.getElementById('checkboxPowerUnit') is giving you a null object, then that object does not exist

http://www.w3schools.com/JS/tryit.as..._input_checked
Nov 3 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.