Results 1 to 1 of 1

Thread: help with list checkboxes

  1. #1
    Join Date
    May 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help with list checkboxes

    Hello everybody, i'm starting with javascript and i have this problem: if you select an item in a dropdownlist then you should get a list of checkboxes acording to the item selected. The problem is that i need the checkboxlist inside a particular div (div id='products'). How can i do it? This is the code i have:
    <script>
    function favBrowser(){
    var listCheckboxes ="";
    var mylist=document.getElementById("myList");
    valueSelected = mylist.options[mylist.selectedIndex].value;
    switch (valueSelected)
    {case "Fruits":
    var product = new Array();
    product[0] = "apple";
    product[1] = "banana";
    product[2] = "ananas";
    break;
    case "Vegetables":
    var product = new Array();
    product[0] = "carrot";
    product[1] = "peper";
    product[2] = "tomate";
    break;
    case "Fish":
    var product = new Array();
    product[0] = "Salmon";
    product[1] = "tuna";
    product[2] = "octopus";
    break;
    }
    for (x in product)
    {
    listCheckboxes += "<input type='checkbox' value='"+ mycars[x] +"'>" + mycars[x] + "<br />";}
    document.getElementById('products').innerHTML = listCheckboxes;
    }
    }
    </script>
    <body>
    <div id="content">
    <form><select id="myList" onChange="favBrowser()">
    <option selected>
    <option value="Fruits">Fruits</option>
    <option value="Groenten">Groenten</option>
    <option value="Conservas">Conservas</option>
    </select></form>
    </div>
    <div id="products"></div>
    </body>
    Last edited by lalein; 05-12-2008 at 11:15 AM.

Bookmarks

Posting Permissions

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