Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2002
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to create checkbox

    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.

    Thanks,
    Nitesh

  • #2
    New Coder
    Join Date
    Jun 2002
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Computers are simple for the complex mind, yet complex for the simple mind

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Something like this?

    Code:
    <html>
    
    <head>
    <script>
    
    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: ;">';
    }else{
    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>';
    
    document.write(htm);
    
    function changedrop() {
    for (x=0;x<choices;x++) {
    document.getElementById("choices"+x).style.display = 'none';
    }
    document.getElementById("choices"+document.form1.drp.selectedIndex).style.display = '';
    }
    </script>
    </head>
    
    <body>
    
    
    </body>
    
    </html>
    Note:

    If the you enter:
    drop[2][1] = "Choice Three One";
    the name of the checkbox will be:
    c2c1
    so....
    document.form1.c2c1...
    Last edited by x_goose_x; 07-31-2002 at 04:55 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •