Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox

Status
Not open for further replies.

stevenk140

Programmer
Joined
Nov 20, 2003
Messages
34
Location
CA
I am using asp.net and have a javascript function. I would like to get all my items out of a multi-selection list box. How would I set up the function and how would I cycle through the selected items?
 
you can use a function like this to get all the items that have been selected from the listbox.

function selectedId(obj) {
var selected_Id = new Array();
var x=0;

for(var i=0; i<obj.selectBox.length; i++) {
if(obj.selectBox.selected) {
var selectedId = obj.selectBox.value;
selected_Id[x] = selectedId;
x++;
}
}
return selected_Id;
}
 
I am not too sure if I am doing this right

page.aspx.cs
private void Page_Load(object sender, System.EventArgs e)
{
btnTrend.Attributes.Add(&quot;onclick&quot;,&quot;MultiTrendWindow(RealTime.lstMultPnts);&quot;);
}

page.aspx
<javascript stuff>
function MultiTrendWindow (listbox) {
var selected_Id = new Array();

for(var i=0; i<listbox.selectBox.length; i++) {
var selectedId = listbox.selectBox[i ].value;
selected_Id[i ] = selectedId;
}

alert(selected_Id[0].toString());
}
 
did you try the code I posted????
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top