Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7188557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:06:40+00:00 2026-05-28T19:06:40+00:00

I am creating tables with the appendchild method. They contain checkboxes. I would like

  • 0

I am creating tables with the appendchild method. They contain checkboxes. I would like to be able to have the user to click a checkbox and have it run a function. I need the function to access the other checkbox and see if its checked or not. Currently I can’ seem to reference the table or checkboxes at all.
My code for creating the table is:

function makeTable() {
    var ItemA = Item.ItemName.options[Item.ItemName.options.selectedIndex].text;
    var myParagraph=document.getElementById("myLine");
    myForm = document.createElement("FORM");
    mytable = document.createElement("TABLE");
    mytablebody = document.createElement("TBODY");

            var CB_Format = document.createElement('input');
            CB_Format.type = 'checkbox';
            CB_Format.name= "CB_Test";
            CB_Format.value= 1;
            CB_Format.setAttribute("name", "CBTest2");
            CB_Format.onclick = changeColor;
            theCell.appendChild(CB_Format);

            var CB_Delete = document.createElement('input');
            CB_Delete.type = "checkbox";
            CB_Delete.name = "CB_Test";
            CB_Delete.setAttribute("name", "CBTest2");
            CB_Delete.value = 2; 
            CB_Delete.onclick = answer; 
            theCell.appendChild(CB_Delete);

My understanding is that my solution should be as simple as alert(document.form.checkbox.checked) but no matter what combination of possible names I try I get the error that it is null or not an object in both ie8 and firefox.
Thank you for your help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:06:41+00:00Added an answer on May 28, 2026 at 7:06 pm
    > function makeTable() {
    >      var ItemA = Item.ItemName.options[Item.ItemName.options.selectedIndex].text;
    >      var myParagraph=document.getElementById("myLine");
    >      myForm = document.createElement("FORM");
    >      mytable = document.createElement("TABLE");
    >      mytablebody = document.createElement("TBODY");
    

    If you don’t declare variables with var, they become global variables when first evaluated. Always declare variables.

    >          var CB_Format = document.createElement('input');
    >          CB_Format.type = 'checkbox';
    >          CB_Format.name= "CB_Test";
    >          CB_Format.value= 1;
    >          CB_Format.setAttribute("name", "CBTest2");
    

    The above line changes the name property from the value assigned a couple of lines earlier, why do both? Just assign the correct value to the name property once:

    CB_Format.name = "CBTest2";
    

    The same goes for the use of setAttribute later. Note that setting the value of a property doesn’t always change the associated attribute in some browsers, so always use properties unless there is a specific reason to use setAttribute,

    […]

    My understanding is that my solution should be as simple as
    alert(document.form.checkbox.checked) but no matter what combination
    of possible names I try I get the error that it is null or not an
    object in both ie8 and firefox. Thank you for your help

    Form controls are made available as named properties of the form element. If there is more than one control with the same name, they are in a collecion. Assigning different values to the name property and attribute is asking for trouble. It should be that the second assignment overwrites the first, but no doubt there is a browser somewhere that will keep both values (one for the attribute and the other for the property).

    The simple solution is to always use properties and only assign one value. If you want the name to be CBTest2 (since that is the second one assigned), then when the input is added to the form and the form to the document it will be available as:

    document.forms['formName'].elements['CBTest2']
    

    If the names are valid identifiers, then shorthand dot notation can be used:

    document.formName.CBTest2
    

    Since you have two elements with that name, the returned value will be a collection (a little like an array), so to get the first one, use:

    document.formName.CBTest2[0]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating checkboxes through appendchild. I want to be able to check their
Does anyone have any suggestions for creating meta tables in a database? These tables
Making my first steps with NHibernate, I'm trying to have it creating my Tables
Initialization would include creating all the required tables, constraints and populating the tables. edit:
im trying to understand the process of creating tables in ruby-on-rails 3. i have
I have problems with creating tables & foreign key. (errno:150) here is a screenshot
I have installed mysql Query browser for creating tables/ views/ procedures (In Ubuntu) But
I'm creating two tables like this: CREATE TABLE abc ( id INTEGER NOT NULL
I have a huge script for creating tables and porting data from one server.
When creating database tables I'm often stumped when trying to name my time/date/timestamp fields.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.