View Full Version : How to create checkbox

07-31-2002, 03:32 PM
Here is my question ...

How can I create check-box dynamically using javascript?
I have this dropdown box and want to create checkboxes depending upon what option you have selected.

Please suggest me what would be the best way to deal this situation, without using server side scripting.


07-31-2002, 04:10 PM
you don't have to use javascript to create the check boxes, you can use a document.write to use different checkboxes based upon the user's decision.

07-31-2002, 04:48 PM
Something like this?



choices = 3; // How many choices do you want?

drop = new Array();
for (x=0;x<choices;x++) {
drop[x] = new Array();

// Drop items //
drop[0][0] = "Category One";
drop[0][1] = "Choice One One";
drop[0][2] = "Choice One Two";
drop[0][3] = "Choice One Three";

drop[1][0] = "Category Two";
drop[1][1] = "Choice Two One";
drop[1][2] = "Choice Two Two";

drop[2][0] = "Category Three";
drop[2][1] = "Choice Three One";
drop[2][2] = "Choice Three Two";
drop[2][3] = "Choice Three Three";
// Drop items //

htm = '<form name="form1">'+
'<select size="1" name="drp" onchange="changedrop();">';
for (x=0;x<choices;x++) {
htm += '<option>'+drop[x][0]+'</option>';
htm += '</select><br>';
for (x=0;x<choices;x++) {
if (x==0) {
htm += '<div id="choices'+x+'" style="display: ;">';
htm += '<div id="choices'+x+'" style="display: none;">';
for (y=0;y<drop[x].length-1;y++) {
htm += '<input type="checkbox" name="c'+x+'c'+y+'">'+drop[x][y+1]+'<br>';
htm += '</div>';
htm += '</form>';


function changedrop() {
for (x=0;x<choices;x++) {
document.getElementById("choices"+x).style.display = 'none';
document.getElementById("choices"+document.form1.drp.selectedIndex).style.display = '';





If the you enter:
drop[2][1] = "Choice Three One";
the name of the checkbox will be:

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum