|
-
Feb 16th, 2001, 04:28 AM
#1
Thread Starter
Hyperactive Member
Hi,
I have a combobox on my asp page
Example:
Code:
<select name="test">
<option value=a>aaa</option>
<option value=b>bbb</option>
<option value=c>ccc</option>
</select>
(I've retreived the data from the database.)
Is there any way I can get the selected text using asp. using request.form("test") will only give me the value and not the text.
Any ideas anyone???
Thanx
-
Feb 16th, 2001, 06:20 AM
#2
Junior Member
I think this is it...
Afraid I can't give a very specific answer but I think you might need the Javascript manual for this one...
Create a hidden field in the form (this will be to hold the value of the selected text)
Then you can use Javascript to create a function that gets called by the form OnSubmit event...
..hees the form declaration:
<FORM NAME="myForm" onSubmit="return GetSelectedText()">
The function should use the selectedIndex property of a select box to detect the selected item and it´s text...
something like ...
function GetSelectedText(){
this.form.myhiddenfield.value
= this.form.myselectfield[selectedIndex].text;
return true;
}
NB Netscape is sensitive about the case of "selectedIndex" so use a small "s" and a large "I"!
...then the form gets submitted & you´ve got the selected text.
...This is pretty much "off the top of my head". No doubt somebody will send in the exact code, or a better solution... but if not, here´s a starter
-
Feb 16th, 2001, 12:22 PM
#3
-
Feb 16th, 2001, 03:18 PM
#4
you might want to add the text to the value and then trim it off again? so you end up with both values at once.
good luck
-
Feb 17th, 2001, 12:55 AM
#5
Thread Starter
Hyperactive Member
Thanx everyone,
It works in javascript but needed to do it from ASP. anyway figured it out. I added both fields from the database to the value(i needed the value coz i have to insert it back into the database) separated by a "-" and then used the split function to separate them.
Thanx again.
-
Feb 19th, 2001, 12:07 AM
#6
Fanatic Member
Hi Rammy,
I always thought the correct way was to use the id property....
Code:
<select name="test">
<option id="a" value=a>aaa</option>
<option id="b" value=b>bbb</option>
<option id="c" value=c>ccc</option>
</select>
and when you slcik the submit button and send it to the form that does the processing....
Simply
Code:
Select Case Request.Form("test")
Case "a"
' something here
Case "b"
' something here
Case "c"
' something here
End Select
DocZaf
{;->
-
Feb 19th, 2001, 11:01 PM
#7
Thread Starter
Hyperactive Member
Hi Zaf,
but whats the difference between using id" and "value" ????
-
Feb 19th, 2001, 11:29 PM
#8
Fanatic Member
Hi Rammy,
I think ID is an Attribute and Value is content
Its to do with where it occurs in the tag.
<TAGX attributes here>Content here</TAGX>
DocZaf
{;->
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|