How to See/Display the checkboxes that are supposedly dynamically created.

vlad2k9's Avatar, Join Date: Jan 2009
Newbie Member
Hello,
I have a <textarea> and a few lines in it. I have isolated the lines - as a manner of questions. Now, I want to dynamically generate a set of <checkboxes> where each line will be an option, just like this:

[ ] lastline
[ ] one before the last
[ ] . . .
[ ] . . .
[ ] second line
[ ] first line

where each pair of brackets is the ACTUAL checkbox. It is like an online test

I found the following portion of code on the web:

************************************************** ***********

Because I always forget how to create checkboxes dynamically in JavaScript so Internet Expoler will be happy:

var i = document.createElement("input");
i.type = "checkbox";
i.className = "CheckBox";
i.id = "uniqueID";
// this is what I forget - Firefox allows .checked, IE must have .defaultChecked
i.defaultChecked = false;
// always use labels
var l = document.createElement("label");
// ALWAYS use for attributes on your labels. FF allows .for, IE must have .htmlFor
l.htmlFor = "uniqueID";
l.appendChild(document.createTextNode("checkbox label"));

************************************************** ************************

Could you please tell me where in the code above the actual checkboxes are displayed?
Just for testing purposes, I did put the above code between <script></script> tags, and
named it "create_them()"; then I called it from the inside of my html <body> from an "onclick" button event in my form. Just like this:
. . .
. . .
<input type="button" onclick="create_them()" value="create boxes"/>
. . .
. . .
I can't understand the workings of that code that I found on the web, all i get is a blank screen.

Could you please shed some light as of what the workings of the code in question will be? Do I need to add something else?
I also found some tree generator in JavaScript in this same forum, but seems to be too complicated although neatly coded.

Your help will be greatly appreciated.

Thanks beforehand.

vlad2k9
0
skp819's Avatar
Contributor
you can learn it from the w3schools.com