Solved

How to get desc of items in select list.

Posted on 2001-08-16
9
252 Views
Last Modified: 2006-11-17
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
0
Comment
Question by:jeremiahscott
  • 4
  • 4
9 Comments
 

Author Comment

by:jeremiahscott
ID: 6393790
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
0
 
LVL 9

Expert Comment

by:msdixon
ID: 6393799
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);
0
 

Author Comment

by:jeremiahscott
ID: 6393822
welp, i wanted to do this part server side. is it possible?
0
 
LVL 9

Expert Comment

by:msdixon
ID: 6393857
are you trying to BUILD a drop down from a form element that was posted?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:jeremiahscott
ID: 6393878
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.
0
 
LVL 5

Expert Comment

by:raizon
ID: 6394005
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>
0
 
LVL 9

Accepted Solution

by:
msdixon earned 50 total points
ID: 6394201
i'm doing the same thing, but it's all client side javascript:

*********** only tested in ie 5.01+ **********

function selectItem(strItem)
{
     var objTo = eval('document.forms[0].frmSelected' + strItem);
     var objFrom = eval('document.forms[0].frm' + strItem);
     if (typeof(objFrom) == 'object' && typeof(objTo) == 'object')
     {
          var objOption = document.createElement("OPTION");
          objOption.text = objFrom.options[i].innerText;
          objOption.value = objFrom.options[i].value;
          objTo.add(objOption);
          }              
          eval('divSelect' + strItem + '.innerHTML = divSelect' + strItem + '.innerHTML');
          eval('divSelected' + strItem + '.innerHTML = divSelected' + strItem + '.innerHTML');
     }
}

****************************
html looks like
****************************

<table border=0 cellpadding=3 cellspacing=0>
     <tr>
          <td>
          <div id="divSelectFields" style="position:relative;top:0;left:0;visibility:visible">
               <select name="frmFields" multiple size=10  style="width:125">
               <!-- put options here -->
               </select>
                    </div>
                    </td>
                    <td>
                         <input type="button" value=">" id=btnSelectFields name=btnSelectFields
                              onclick="selectItem('Fields')"><br>
                         <input type="button" value="<" id=btnRemoveFields name=btnRemoveFields
                              onclick="removeItem('Fields')">
                    </td>
                    <td valign=bottom>
                    <div id="divSelectedFields" style="position:relative;top:0;left:0;visibility:visible">
                         </div>
                    </td>
               </tr>
          </table>

........... i just showed the selectItem function ..........



0
 

Author Comment

by:jeremiahscott
ID: 6397981
yea, i ended up doing it client side. it works well, but i like to do as much as possible server side.
0
 
LVL 9

Expert Comment

by:msdixon
ID: 6398009
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.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 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

19 Experts available now in Live!

Get 1:1 Help Now