populating listbox in ajax

Posted on 2007-10-18
Last Modified: 2012-05-05
i am trying to populat listbox from the datagrid.datagrid i am using has checkboxes and when the user checks the checkboxes and then clicks the submit button,then the checked items should be displayed in listview control.i am using ajax--jscript.
thnks in advance
Question by:pranathi27
    LVL 82

    Accepted Solution

    Assumming you have:
    <select id="myList" name="DropdownList"></select>
    <input type="checkbox" name="dept" value="Engineering"/>
    <input type="checkbox" name="dept" value="Mathematics"/>

    You can try:
    var chkBoxes=document.getElementsByName("dept");
    var sel=document.getElementById("myList");
    var options="";
    for(var i=0; i < chkBoxes.length;++i)
        options+="<option value='"+chkBoxes[i].value+"'>"+chkBoxes[i].value+"</option>";
    LVL 2

    Assisted Solution

    the above is good, one addition i would suggest would be to stay away from string concats to append nodes. use the following to add to the box, once you get your data back from the ajax return.

    function fillSelect(elem, arr)
        elem.innerHTML = '';
        for(var i = 0; i < arr.length; i++)
            var nOpt = document.createElement("option");
            var nText = document.createTextNode(arr[i]);
            nOpt.value = arr[i];

    Open in new window

    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Suggested Solutions

    This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now