Click to See Complete Forum and Search --> : asp and forms.......
rammy
Feb 16th, 2001, 03:28 AM
Hi,
I have a combobox on my asp page
Example:
<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
shaunmccallig
Feb 16th, 2001, 05:20 AM
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
Cander
Feb 16th, 2001, 11:22 AM
remove the value=
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
rammy
Feb 16th, 2001, 11:55 PM
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. :)
Zaf Khan
Feb 18th, 2001, 11:07 PM
Hi Rammy,
I always thought the correct way was to use the id property....
<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
Select Case Request.Form("test")
Case "a"
' something here
Case "b"
' something here
Case "c"
' something here
End Select
DocZaf
{;->
rammy
Feb 19th, 2001, 10:01 PM
Hi Zaf,
but whats the difference between using id" and "value" ????
Zaf Khan
Feb 19th, 2001, 10:29 PM
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
{;->
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.