Solved

How to get desc of items in select list.

Posted on 2001-08-16
9
258 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
Industry Leaders: 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 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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

631 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