SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jun 2004
    Location
    germany
    Posts
    263
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Get Text from a Combo Box

    Hello Select Control in HTML (COMBO BOX) does have 2 values

    <Code Value> <Text Value>

    Now say my Select id= SelectID
    then i can get the value of that using
    document.getElementByID("SelectID").value

    <option value=100> mystring</option>
    document.getElementByID("SelectID").value
    Now this will get me 100
    but i want to get mystring
    I Tried
    document.getElementByID("SelectID").text
    but it didnt worked. How i can get the text value using javascript.

    Thanks in advance

    Regards
    Knowledge is all about Sharing

  2. #2
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    document.getElementByID("SelectBoxName").options[document.getElementByID("SelectBoxName").selectedIndex].value

    should work for ya of course setting document.getElementByID("SelectBoxName") to a var first will speed things up

    to get the text do .text instead of .value

  3. #3
    SitePoint Addict
    Join Date
    Jun 2004
    Location
    germany
    Posts
    263
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    document.getElementByID("SelectBoxName").options[document.getElementByID("SelectBoxName").selectedIndex].text
    that did the trick
    Thank you very much (Lab45) for your reply.
    Regards
    Knowledge is all about Sharing


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •