Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to get desc of items in select list.

Posted on 2001-08-16
9
Medium Priority
?
260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 200 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

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

670 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