Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 6th, 2007, 02:13 AM
Registered User
 
Join Date: Mar 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default get the text and not the value from a selectBox

Hi, I have the following code which works fine...
Request.Form.Key() that gets the name of the object, then
Request.Form.Item() that gets the value of the selected option, but I need to get the Text also and don't know how to do it.
 
Old March 6th, 2007, 08:36 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Request.Form("fieldname") will return the value.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old March 8th, 2007, 08:12 AM
Registered User
 
Join Date: Mar 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm sorry, I guess i didn't explained very well.

have this problem that I need to get the text out of a select box in classic ASP but haven't found how and I did search it over the net but nothing, let me explain it with an example:

if I have...

<select name="selOpt1" id="selOpt1">
         <option value="0" selected="selected">Select One</option>
         <option value="1.00">First Option</option>
         <option value="2.00">Second Option</option>
         <option value="3.00">Third Option</option>
       </select>

if I use Request.Form.Key() I get the name of the object, in this example "selOpt1" and if I use Request.Form.Item() I get the value of the selected option, lets say "1.00" or "2.00" etc, but what if need the text from the selected option? lets say "First Option" or "Second Option" that's actually my problem, don't know how to do it.

another thing that I probably need to mention is that I'm using these code on a second page, that collects the values from a form on the first page.

thanx
 
Old March 9th, 2007, 07:04 AM
Authorized User
 
Join Date: Jan 2007
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to saurabhj Send a message via Yahoo to saurabhj
Default

That is not possible. You have to set the name as value of that element

 
Old March 9th, 2007, 09:35 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Unfortunately, saurabhj is correct, at least using the Request object. You may be able to get this information using a client side javascript but the request object is only going to get you the value.

In .NET doing what you want is not only possible, it is extremely easy.

Dim s1, s2 as String
s1 = selOpt.SelectedItem.Value
s2 = selOpt.SelectedItem.Text

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old March 9th, 2007, 11:20 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

[It is puzzling as to why you need the text of the selected item. What is your purpose for needing that?

If there is an actual need to have both the value and the text, you can concatenate the two with a delimiter and place them both in the value as you build the select box.

Code:
<select name="selOpt1" id="selOpt1">
    <option value="0|None" selected="selected">Select One</option>
    <option value="1.00|First Option">First Option</option>
    <option value="2.00|Second Option">Second Option</option>
    <option value="3.00|Third Option">Third Option</option>
</select>
Then your code needs that handles the submit needs to parse the value to retrieve the values you need.

Woody Z
http://www.learntoprogramnow.com
How to use a forum to help solve problems
 
Old March 9th, 2007, 12:13 PM
Registered User
 
Join Date: Mar 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi again, first of all thank you saurabhj, dparsons & woodyz for your time. I'm creating a very basic form where the user select Yes or No with a select box and needed those selections on an email, so I'm using 2 files, one for the form and the other to create the email, the thing is that for every selection they made (Yes or No) it must have a value so that I can calculate the points they get, I know I can make some work around like the one that woodyz helpfully suggested, but wanted to make sure that there was no actual code for ASP that I can use to get the text.

Many thanks to all of you.

 
Old March 9th, 2007, 12:59 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Conceptually, the value and the text are two different views of the same piece of data - the text is the human readable view and the value is the code readable view, and therefore it is not common to need to read the text of the select box in a request. This is because in the typical case you can always determine what the text is by using the value as the key.

Woody Z
http://www.learntoprogramnow.com
How to use a forum to help solve problems





Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Text(Sql Server Text Field) to Image(JPG) srinivas72 ADO.NET 2 February 13th, 2009 06:31 PM
2 table fields into 1 dropdown selectbox sdagger Classic ASP Basics 2 September 23rd, 2008 03:42 PM
Extract text from text file & put in dropdown box tsukey Beginning PHP 5 July 20th, 2004 09:49 PM
Ch3, P.76 - text.html/text.php not working Hostile BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 4 May 15th, 2004 11:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.