Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Getting option's text value

Reply
Thread Tools

Getting option's text value

 
 
Raul
Guest
Posts: n/a
 
      04-10-2007
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!

 
Reply With Quote
 
 
 
 
Adrienne Boswell
Guest
Posts: n/a
 
      04-10-2007

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)

--
Adrienne Boswell at work
Administrator nextBlock.com
http://atlas.nextblock.com/files/
Please respond to the group so others can share

 
Reply With Quote
 
 
 
 
vinodkus@gmail.com
Guest
Posts: n/a
 
      04-11-2007
On 10 Apr, 13:13, "Raul" <(E-Mail Removed)> wrote:
> 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>


 
Reply With Quote
 
Raul
Guest
Posts: n/a
 
      04-13-2007
On Apr 11, 2:00 am, (E-Mail Removed) wrote:
> 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!


 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      04-13-2007
Raul wrote:
> 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.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


 
Reply With Quote
 
Raul
Guest
Posts: n/a
 
      04-13-2007
On Apr 13, 2:00 pm, "Bob Barrows [MVP]" <(E-Mail Removed)>
wrote:
> 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?


 
Reply With Quote
 
Dave Anderson
Guest
Posts: n/a
 
      04-13-2007
Raul wrote:
> 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.



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.


 
Reply With Quote
 
Dave Anderson
Guest
Posts: n/a
 
      04-13-2007
Raul wrote:
> 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.



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Textbox.text not getting value seanmle@gmail.com ASP .Net 1 02-23-2006 10:01 AM
Textbox.text not getting value seanmle@gmail.com ASP .Net 2 02-23-2006 05:27 AM
Getting ID, calling url, search for value, return value Tim Fröglich ASP .Net Web Services 1 01-10-2006 09:18 PM
Populating a text field and then getting its value Imran Aziz ASP .Net 7 08-10-2005 03:13 PM
Getting value from asp:label into javascript input value Dwizz Javascript 10 08-07-2005 02:28 AM



Advertisments