How do I indicate that a checkbox should be checked?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • andersond
    New Member
    • Feb 2007
    • 110

    How do I indicate that a checkbox should be checked?

    I have a form named "FrontPage_Form 2" and a checkbox named "checkboxPowerU nit"; and, I want to programmaticall y change whether or not it is checked by default based on a selection made in a selection box. I have tried:

    Code:
    document.FrontPage_Form2.checkboxPowerUnit.checked=true;
    document.all.checkboxPowerUnit.checked=true;
    document.form[0].checkboxPowerUnit.checked=true;
    document.form[0].checkboxPowerUnit[0].checked=true;
    document.FrontPage_Form2].checkboxPowerUnit[0].checked=true;
    and every one results in an error saying "document.whate ver" is null or not an object. Can anyone tell me how to indicate that this checkbox should be checked or unchecked?
    Last edited by Dormilich; Nov 3 '09, 09:03 PM. Reason: Please use [code] tags when posting code
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Assign it an id and then use document.getEle mentById(idstri ng)

    Comment

    • andersond
      New Member
      • Feb 2007
      • 110

      #3
      it has an id. the id and the name are the same.

      Comment

      • andersond
        New Member
        • Feb 2007
        • 110

        #4
        Code:
        document.getElementById('checkboxPowerUnit').checked=true;
        document.getElementById('checkboxPowerUnit').value="YES";
        also do not work
        Last edited by Dormilich; Nov 3 '09, 09:05 PM. Reason: Please use [code] tags when posting code

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          Are you perhaps running this script before the page has loaded?
          if document.getEle mentById('check boxPowerUnit') is giving you a null object, then that object does not exist

          The W3Schools online code editor allows you to edit code and view the result in your browser

          Comment

          Working...