Results 1 to 8 of 8

Thread: asp and forms.......

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    India
    Posts
    298

    Question

    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

  2. #2
    Junior Member
    Join Date
    Feb 2001
    Location
    Madrid, Spain
    Posts
    17

    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

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    remove the value=
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4
    Guest
    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

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    India
    Posts
    298

    Cool

    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.

  6. #6
    Fanatic Member
    Join Date
    Jan 1999
    Location
    UK
    Posts
    554
    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
    {;->

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    India
    Posts
    298
    Hi Zaf,

    but whats the difference between using id" and "value" ????

  8. #8
    Fanatic Member
    Join Date
    Jan 1999
    Location
    UK
    Posts
    554
    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
  •  



Click Here to Expand Forum to Full Width