Link to home
Start Free TrialLog in
Avatar of jeremiahscott
jeremiahscott

asked on

How to get desc of items in select list.

hello-

im trying to cycle thru my list box and get both the value and desc of all the options in it. i use client side javascript to select all the items in the list then call

for(var i=i;i<=Request.Form("lstAvailableCats").Count;i++){
  Response.Write(Request.Form("lstAvailableCats").Item(i));                                                                  
}


but im not getting any output. any help would be great.
thanks - js
Avatar of jeremiahscott
jeremiahscott

ASKER

typographical error.

    for(var i=1;i<=Request.Form("lstAvailableCats").Count;i++){
                                             Response.Write(Request.Form("lstAvailableCats").item(i));                                                                  
                                        }

i can get all the values now but not the desc's
try this.

var strMsg = '';
for (var i = 0; i < document.frmName.selectName.options.length; i++)
{
     strMsg += 'text:' + document.frmName.selectName.options[i].text + '\n';
     strMsg += 'value:' + document.frmName.selectName.options[i].value + '\n';
}
alert(strMsg);
welp, i wanted to do this part server side. is it possible?
are you trying to BUILD a drop down from a form element that was posted?
this is kinda trickey. i have two select boxes, avaiable categories and select categories. the first time the page is loaded the available list is filled from a database. i then allow people to move from the available box to the selected box via client side javascript.  if the user fails to fill in one of the fields on the page i reload it and fill back in the fields that they filled in. i want to fill back in both select boxes with the correct values. i can't think of a way to do this server side, so i may have to do it client side.
To do it serverside you need to build the select box something like this.

<select name="selectName">
<%
' get your recordset
Do while not rs.EOF
 strOut = strOut & "<option value='" & rs("fieldname") & "'"
 If Request.Form("selectName") = rs("fieldname") Then
  strOut = strOut & " selected>" & rs("fieldname") & "</option>"
 Else
  strOut = strOut & ">" & rs("fieldname") & "</option>"
 End If
 rs.MoveNext
Loop
%>
</select>
ASKER CERTIFIED SOLUTION
Avatar of msdixon
msdixon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yea, i ended up doing it client side. it works well, but i like to do as much as possible server side.
server side is good, but it's important not to hit the server too many times. it makes pages an annoyance rather than a help... even on an intranet application.

glad it worked for you.

p.s. did it work with netscape? i know they support the document.createElement() method.