#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Posts
    6
    Rep Power
    0

    Question How to access text between Option Tags in JavaScript?


    Hi all.... Consider the following..

    <SELECT Name='selTest'>
    <OPTION value='1'>Test Text1</OPTION>
    <OPTION value='2'>Test Text2</OPTOIN>
    <OPTION value='3'>Test Text3</OPTION>
    </SELECT>

    Is it possible for me to retrieve the text contained between the <OPTION>I need this</OPTION> In JavaScript?? I know i could set the value = to the text but this info is coming from the database and could be redundant. Thanks in advance for all replies.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2003
    Posts
    1,014
    Rep Power
    15
    Assuming your form has a name 'myform', this will alert the text of the second option 'Test Text2'.
    Code:
    <div onclick="alert(document.forms['myform'].selTest[1].text)">show the text of the second option</div>
    Hope this helps,
    Jeroen

IMN logo majestic logo threadwatch logo seochat tools logo