SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Sep 2011
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Drop Down (Option Tag)

    Hi, my site has a drop down menu on it and i am using a JS script to display the chosen text from the drop down menu at the bottom of a page... my question is... the JS script reads the text in the value="" below and not the text in between the <option> tags

    <option value="sample_text">Sample Text</option>

    Is it ok to display normal text (it is not 2 words instead of 1) in the value="" for example <option value="Sample Text">Sample Text</option>

    Thanks in advance for your help...

  2. #2
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,278
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by oo7ml
    Is it ok to display normal text (it is not 2 words instead of 1) in the value="" for example <option value="Sample Text">Sample Text</option>
    According to the W3C, the value attribute of OPTION elements is CDATA. It seems to me it should accept spaces so long as it's in quotes. This isn't true for all CDATA in HTML though so a validator check would be best.

    You could also choose to use Javascript to grab the text inside instead of the value. This is referred to by options[particularOption].text.

  3. #3
    SitePoint Addict
    Join Date
    Sep 2011
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok cool, thanks for your help...

  4. #4
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,278
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    I've had the same problem myself with options. They're kinda picky.

  5. #5
    SitePoint Addict
    Join Date
    Sep 2011
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok cool, what did you do in the end...

  6. #6
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,278
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    I think I used .text for the time where I wanted to do something with the [selectedIndex], and not .value. .value I used when I just needed to know which option was chosen in order to do something else unrelated to the text in the option.

  7. #7
    SitePoint Addict
    Join Date
    Sep 2011
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok cool, thanks for your help...


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
  •