Solved

How to get desc of items in select list.

Posted on 2001-08-16
9
253 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
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 …

914 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

17 Experts available now in Live!

Get 1:1 Help Now