tags:

views:

25

answers:

5

i am trying to use like

var modelLength     = document.getElementsByName("FK_BrandID")[0].text;

when i try to alert this it prints only undefined.. is this not proper..?

A: 

AFAIK, no element has a text property. Perhaps you are looking for value?

David Dorward
A: 

Have a look

org.life.java
+1  A: 

I think this is what you're after:

var sel = document.getElementsByName("FK_BrandID")[0];
var modelLength = sel.options[sel.selectedIndex].text;

You can give it a try here

Nick Craver
+1  A: 

You can do like this:

var index = document.getElementById("FK_BrandID").selectedIndex;
var value = document.getElementById("FK_BrandID").options[index].text;
alert(value);

That will give you the text of selected option in the select box. To get the value of select box instead, use value

var value = document.getElementById("FK_BrandID").value;
alert(value);
Sarfraz
There's no need to fetch the element twice...also id != name :)
Nick Craver
A: 

Hello, everything you read above is correct, the problem in your code was the options word missing, with this your code should worked:

var modelLength = document.getElementsByName("FK_BrandID").options[0].text;

Torres