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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:42:14+00:00 2026-06-10T19:42:14+00:00

OK I’ve been trying to append some checkbox’s to a div dynamically based on

  • 0

OK I’ve been trying to append some checkbox’s to a div dynamically based on the number of columns in a dataset. So I thought d3 would be the way to go, simply append the input with the appropriate attributes and some text for the label determined from the data. I’ve tried the following code;

d3.select("body").selectAll("input")
.data([11, 22, 33, 44])
.enter().append("input")
.attr("checked", true)
.attr("type", "checkbox")
.attr("id", function(d,i) { return i; })
.attr("onClick", "change(this)")
.attr("for", function(d,i) { return i; })
.text(function(d) { return d; });

Which results in 4 checkboxs on the page but no labels.

What’s really strange is that when I inspect the elements the html generated seems to be what I’m after as shown below.

<input checked="true" type="checkbox" id="0" onclick="change(this)" for="0">11</input>
<input checked="true" type="checkbox" id="1" onclick="change(this)" for="1">22</input>
<input checked="true" type="checkbox" id="2" onclick="change(this)" for="2">33</input>
<input checked="true" type="checkbox" id="3" onclick="change(this)" for="3">44</input>

When I use this on a page I get exactly what I’m after.

I’m sure I’m missing something extremely simple, but for the life of me I can’t see what it is. Any help gratefully accepted!

  • 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-06-10T19:42:16+00:00Added an answer on June 10, 2026 at 7:42 pm

    Your main problem is that you can’t put text in between <input> tags like that. They are self-closing like <input />. You should use the <label> element for that text.

    Other problem is that ID’s must begin with a letter (at least, before HTML5), so id="1" won’t work, but id=a1" will.

    That said, this code solves those two problems

    d3.select("body").selectAll("input")
    .data([11, 22, 33, 44])
    .enter()
    .append('label')
        .attr('for',function(d,i){ return 'a'+i; })
        .text(function(d) { return d; })
    .append("input")
        .attr("checked", true)
        .attr("type", "checkbox")
        .attr("id", function(d,i) { return 'a'+i; })
        .attr("onClick", "change(this)");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to append some JSON data from the last.fm API, I have been
Im trying to append some JSON data from the last.fm API, I have been
I've been trying to create some php code that would let me take input
I have been trying to export some datagrids in Silverlight to excel, but have
I've been trying to make my classes completely self contained, but I'm having some
Am stuck here. I've been trying to upload some photos and at the same
I am trying to append some text to the end of a file in
Ive been trying to figure out how to get some data i type into
I'd been trying to scrape some date from as asp.net website, the start page
Been trying to figure this out, but can't come up with a good solution

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.