?
Solved

populating listbox in ajax

Posted on 2007-10-18
4
Medium Priority
?
1,282 Views
Last Modified: 2012-05-05
hi
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
0
Comment
Question by:pranathi27
3 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 1000 total points
ID: 20103219
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)
{
  if(chkBoxes[i].checked)
    options+="<option value='"+chkBoxes[i].value+"'>"+chkBoxes[i].value+"</option>";
}
sel.innerHTML=options;
0
 
LVL 2

Assisted Solution

by:ilaird
ilaird earned 1000 total points
ID: 20775198
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];
        nOpt.appendChild(nText);
        elem.appendChild(nOpt);
    }
}

Open in new window

0
 
LVL 1

Expert Comment

by:Computer101
ID: 21091211
Forced accept.

Computer101
EE Admin
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Suggested Courses
Course of the Month17 days, 3 hours left to enroll

864 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