[thelist] JavaScript value of text in an option element

Hassan Schroeder hassan at webtuitive.com
Mon Jan 19 12:56:48 CST 2004


fstorr wrote:

> Using JavaScript I need to validate against the contents of the text in 
> an <option> element (as opposed to the contents of the value attribute), 
> and cannot work out how to do it.  I've tried various things - .value 
> gives me the value of the selected value attribute, but if I try 
> .innerText or .innerHTML I get the values of every <option> element in 
> the dropdown.

innerHTML works for me in Moz/Firebird 0.7(Win), at least ...

<script type="text/javascript">	
function checkthis(thing)
{
	alert(thing.options[thing.selectedIndex].innerHTML);
}
</script>

<select name="trial" onchange="checkthis(this);">
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
</select>

FWIW!
-- 
Hassan Schroeder ----------------------------- hassan at webtuitive.com
Webtuitive Design ===  (+1) 408-938-0567   === http://webtuitive.com

                           dream.  code.





More information about the thelist mailing list