Esteis
0
Q:

how to create checkbox list in javascript

<!DOCTYPE html> 
<html> 
    <head> 
        <title> 
            DOM Input Checkbox Property 
        </title> 
    </head> 
    <body style = "text-align: center;"> 
        <h1 style = "color:green;"> 
            GeeksforGeeks 
        </h1> 
        <h2> 
            DOM Input Checkbox Property 
        </h2> 
        <p>Click the button to create a checkbox.</p> 
        <button onclick="geek()">Click me!</button> 
        <br> 
        <div id = "myDiv"></div> 
        <script> 
        function geek() { 
            var myDiv = document.getElementById("myDiv"); 
              
            // creating checkbox element 
            var checkbox = document.createElement('input'); 
              
            // Assigning the attributes 
            // to created checkbox 
            checkbox.type = "checkbox"; 
            checkbox.name = "name"; 
            checkbox.value = "value"; 
            checkbox.id = "id"; 
              
            // creating label for checkbox 
            var label = document.createElement('label'); 
              
            // assigning attributes for  
            // the created label tag  
            label.htmlFor = "id"; 
              
            // appending the created text to  
            // the created label tag  
            label.appendChild(document.createTextNode('This is the 
                              label for checkbox.')); 
              
            // appending the checkbox 
            // and label to div 
            myDiv.appendChild(checkbox); 
            myDiv.appendChild(label); 
        } 
        </script> 
    </body> 
</html> 
0

New to Communities?

Join the community