Solved

How to get desc of items in select list.

Posted on 2001-08-16
9
254 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 9

Expert Comment

by:msdixon
ID: 6393857
are you trying to BUILD a drop down from a form element that was posted?
0
 

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 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