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

  • Home
  • SEARCH
  • 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 8595637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:29:00+00:00 2026-06-12T00:29:00+00:00

I try to make lines dynamically, the problem is when I add a checkbox

  • 0

I try to make lines dynamically, the problem is when I add a checkbox with label dynamically using javascript does not work. However the one I created with Html by default works correctly.

In fact I want the image that I added (on.png / off.png) replaces the checkbox. When I do it only with html (checkbox + label) the code works, but now I only want to create the element with Javascript, I can chow the label but it when I click It’s not work.

This is all my code :

Main.html

 <HTML>
 <HEAD>
<TITLE>  </TITLE>
<link rel="stylesheet" type="text/css" href="style.css" />
<SCRIPT language="javascript">
    function addRow(tableID) {

        var table = document.getElementById(tableID);

        var rowCount = table.rows.length;
        var row = table.insertRow(rowCount);

        var cell1 = row.insertCell(0);
        var element1 = document.createElement("input");
        element1.type = "checkbox";
        element1.id =  "id2" ;
        cell1.appendChild(element1);

        // Create label
        var label = document.createElement("label");
        label.for =  "id2" ;
        cell1.appendChild(label);

        var cell2 = row.insertCell(1);
        cell2.innerHTML = rowCount + 1;

        var cell3 = row.insertCell(2);
        var element2 = document.createElement("input");
        element2.type = "text";
        cell3.appendChild(element2);


    }

    function deleteRow(tableID) {
        try {
        var table = document.getElementById(tableID);
        var rowCount = table.rows.length;

        for(var i=0; i<rowCount; i++) {
            var row = table.rows[i];
            var chkbox = row.cells[0].childNodes[0];
            if(null != chkbox && true == chkbox.checked) {
                table.deleteRow(i);
                rowCount--;
                i--;
            }

        }
        }catch(e) {
            alert(e);
        }
    }

</SCRIPT>
 </HEAD>
<BODY>
<INPUT type="button" value="Add Row" onclick="addRow('dataTable')" />

<INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" />

<TABLE id="dataTable" width="350px" border="1">
    <TR>
        <TD><INPUT type="checkbox" name="chk"  id="id1" /> <label for="id1" > </label>   </TD>
        <TD> 1 </TD>
        <TD> <INPUT type="text" /> </TD>
    </TR>
  </TABLE>
</BODY>
</HTML>

style.css

 input[type=checkbox] {
  display:none;
}

 input[type=checkbox] + label
 {
   background: url(images/off.png) no-repeat;
   height: 64px;
   width: 64px;
   display:inline-block;
   padding: 0 0 0 0px;
 }

  input[type=checkbox]:checked + label
 {
    background: url(images/on.png) no-repeat;
    height: 64px;
    width: 64px;
    display:inline-block;
    padding: 0 0 0 0px;
  }

Help me please.

  • 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-12T00:29:01+00:00Added an answer on June 12, 2026 at 12:29 am

    Change this

    label.for =  "id2" ;
    

    to this

    label.htmlFor =  "id2" ;
    

    Because some JavaScript implementations didn’t allow keywords/reserved words as object properties, a workaround had to be made for the for property, so they chose htmlFor.

    A similar situation was with .class, which is why they use .className.

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

Sidebar

Related Questions

I try to make a specific MySQL query work with PDO unnamed placeholders, and
I try to make a small script, using c shell, that will take a
I try to make a displaying list with onmouseover() with some links but they
I try to make my ListBox connected to ObservaleCollection be more efficient so for
I try to make an ActiveX by C# with COM-visible. It is a Windows
I try to make an imageview clickable. Actually it is clickable, so that I
I try to make a table header fixed when scoll down on pages. The
I try to make a apps that need barcode scanner, i already can get
I try to make an auto-update feature with my RSS reader application, so it
I try to make a registration form. When user post the fields, i check

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.