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...

Stomme_poes
—
2012-04-11T19:44:53Z —
#2

oo7ml said:

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 [url=http://www.w3.org/TR/html4/types.html#type-cdata]CDATA](http://www.w3.org/TR/html4/interact/forms.html#h-17.6). 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.

oo7ml
—
2012-04-11T20:23:37Z —
#3

Ok cool, thanks for your help...

Stomme_poes
—
2012-04-12T20:53:23Z —
#4

I've had the same problem myself with options. They're kinda picky.

oo7ml
—
2012-04-13T08:57:03Z —
#5

Ok cool, what did you do in the end...

Stomme_poes
—
2012-04-13T09:09:54Z —
#6

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.