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 7174769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:07:42+00:00 2026-05-28T16:07:42+00:00

I am creating checkboxes through appendchild. I want to be able to check their

  • 0

I am creating checkboxes through appendchild. I want to be able to check their state. I know the format is supposed to be document.form.checkboxname.value but no matter what combination of form name or checkbox name I use it doesn’t give me a response.

        var myParagraph=document.getElementById("myLine");
            myForm = document.createElement("FORM");
            myForm.setAttribute("name", "myForm2");
            mytable = document.createElement("TABLE");

        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);

To recap I want the answer function to give me an alert if the checkbox is checked or not. Thank you so much!
To clarify what do I replace the form and checkbox with in the alert(document.form.checkbox.value)?

  • 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-28T16:07:43+00:00Added an answer on May 28, 2026 at 4:07 pm

    CB_Delete.checked should work. See HTMLInputElement on MDN.

    console.log(CB_Delete.checked);
    

    jsFiddle Demo


    • To make your checkbox checked or unchecked, you would do CB_Delete.checked = true or CB_Delete.checked = false respectively. checked is an object property that is expected to have Boolean values. CB_Delete.checked simply queries its current value.

    • In your event handler function, you can reference the element that currently handles the event as this. So from the example in my previous jsFiddle:

      CB_Delete.onchange = function () {
          console.log(this.checked); /* this refers to the checkbox here */
      };
      

      You could use this in your answer function as well.

    • You can read more about handling events on Quirksmode.

    • Note: Using CB_Delete.onchange is a quite old and not really recommended way to attach event handlers most of the time. The use of CB_Delete.addEventListener('change', answer, false) is the right way to do this. Older IEs will have problem with it, but they have attachEvent() instead. You can read about this technique and why to use it on Quirksmode (the article is 3 years old, take this into account when reading things like "Unfortunately few browsers support it at the moment."). To hide the browser differences, you can use a library like jQuery.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating this form with checkboxes that I want to populate from a database.
I'm creating a form that has two checkboxes yes and no. I have added
I'm creating a web form, where in there are around 12-15 Input Fields... You
I'm creating a pretty simple form, and I'm running into an issue with Controls/components
I'm creating some checkbox's from codebehind (adding through Panel.Controls.Add()). My question is: How can
I am creating a survey form that needs to have each question and set
Is it possible to edit a DFM (Delphi's form script format) in such a
I'm creating a system to walk users through a web site. To avoid mistakes
I am trying to check checkboxes based on values in a smarty array. In
I am creating checkboxes with a loop. I would like to uncheck all checkboxes

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.