Getting option's text value

R

Raul

Hi,

I have a select list that gets populated from the DB. When the user
makes a selection I am able to retrieve this value via
Request.Form(...)

However, I am wondering if you can retrieve the text value using ASP??
I know this can be done in JavaScript using the options text
attribute, but it is possible in ASP?

Any input would be appreciated....Thanks!
 
A

Adrienne Boswell

Raul wote:
Hi,

I have a select list that gets populated from the DB. When the user
makes a selection I am able to retrieve this value via
Request.Form(...)

However, I am wondering if you can retrieve the text value using ASP??
I know this can be done in JavaScript using the options text
attribute, but it is possible in ASP?

Any input would be appreciated....Thanks!

You could append the value to the option value, eg: <option value="<
%=rsarr(0,i)%>:<%=rsarr(1,i)%>"><%=rsarr(1,i)%></option>

Then when you get the values
things = split(request.form("that"),":")
optionvalue = things(0)
textvalue = things(1)
 
V

vinodkus

Hi,

I have a select list that gets populated from the DB. When the user
makes a selection I am able to retrieve this value via
Request.Form(...)

However, I am wondering if you can retrieve the text value using ASP??
I know this can be done in JavaScript using the options text
attribute, but it is possible in ASP?

Any input would be appreciated....Thanks!

select.asp
<body>
<form name = form1 method = post action = "PrintSelectList.asp">
<select name = "cboToppings" size = 4 multiple>
<option selected>Cheese
<option selected>Totmato Sauce
<option>Olive Oil
<option>Barbecue Sauce
<option>Pepperoni
<option>Sausage
<option>Mushrooms
<option>Onions
<option>Ham
<option>Pineapple
<option>Green Peppers
<option>Anchovies
</select>
<p>
<input type = submit name = cmdSubmit value = "Deliver It">
</p>
</form>
</body>


PrintSelectList.asp
<body>
<%
dim strSelect
dim i
strSelect = split(Request.Form("cboToppings"), ", ")
length = len(str)
for i = 0 to UBound(strSelect)
response.write strSelect(i) & " "
next
%>
</body>
 
R

Raul

select.asp
<body>
<form name = form1 method = post action = "PrintSelectList.asp">
<select name = "cboToppings" size = 4 multiple>
<option selected>Cheese
<option selected>Totmato Sauce
<option>Olive Oil
<option>Barbecue Sauce
<option>Pepperoni
<option>Sausage
<option>Mushrooms
<option>Onions
<option>Ham
<option>Pineapple
<option>Green Peppers
<option>Anchovies
</select>
<p>
<input type = submit name = cmdSubmit value = "Deliver It">
</p>
</form>
</body>

PrintSelectList.asp
<body>
<%
dim strSelect
dim i
strSelect = split(Request.Form("cboToppings"), ", ")
length = len(str)
for i = 0 to UBound(strSelect)
response.write strSelect(i) & " "
next
%>
</body>

Thanks for the input everyone. In the meantime I thought of a
solution that nobody else posted on here...I personally like it more.
Add an onclick event to the option element. Whenever it gets clicked,
save the text into a hidden form field. This value can then be used
as you like (I needed it to save the user input to the DB)

Cheers!
 
B

Bob Barrows [MVP]

Raul said:
Thanks for the input everyone. In the meantime I thought of a
solution that nobody else posted on here...I personally like it more.
Add an onclick event to the option element. Whenever it gets clicked,
save the text into a hidden form field. This value can then be used
as you like (I needed it to save the user input to the DB)
Sure, that's one of the ways to do this, but why do you like it better?
Now you're at the mercy of a user who can easily disable javascript in
his browser.
 
R

Raul

Sure, that's one of the ways to do this, but why do you like it better?
Now you're at the mercy of a user who can easily disable javascript in
his browser.

Good point on that one, but I know all our users dont have JavaScript
disabled (its not a public site). If they had JavaScript disabled
then the site will not function properly.

To answer your question, I like it better because it seems more
elonquent than adding a delimiter to the value and appending the
description. Its just my opinion obviously, it is largely a stylistic
choice. Does anyone agree or am I on my own on this one?
 
D

Dave Anderson

Raul said:
Thanks for the input everyone. In the meantime I thought of a
solution that nobody else posted on here...I personally like it
more. Add an onclick event to the option element. Whenever it
gets clicked, save the text into a hidden form field. This
value can then be used as you like (I needed it to save the
user input to the DB)

I fail to see how that is an improvement over getting the value from the
database. The advantage of direct DB query is especially acute if the table
you are updating is in the same database as the one you are filling options
from, since you can simply do it in the DB at insert.
 
D

Dave Anderson

Raul said:
Good point on that one, but I know all our users dont have
JavaScript disabled (its not a public site). If they had
JavaScript disabled then the site will not function properly.

You are making far too many assumptions. I, for one, run the NoScript
extension when I browse the web. With it, I can temporarily turn on
scripting for a site, get past the non-working stuff, and turn it back off.
How exactly do you think you could circumvent that?

I don't even know where to begin with the Web Developer extension. There is
almost nothing you can do client-side to prevent me from controlling the
content of my requests. You should, therefore, concentrate on handling
requests, not dictating them.

To answer your question, I like it better because it seems more
elonquent than adding a delimiter to the value and appending
the description.

In the sense that it more explicitly divides the text and value, I agree
that this is a better approach than delimited concatenation. But neither is
robust.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top