Reputation: 7906
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..?
Upvotes: 0
Views: 6710
Reputation: 5400
Everything you read above is correct, the problem in your code was, the options word was missing. with this your code should work:
var modelLength = document.getElementsByName("FK_BrandID")**.options**[0].text;
Upvotes: 0
Reputation: 382696
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);
Upvotes: 1
Reputation: 630389
I think this is what you're after:
var sel = document.getElementsByName("FK_BrandID")[0];
var modelLength = sel.options[sel.selectedIndex].text;
Upvotes: 1
Reputation: 943480
AFAIK, no element has a text
property. Perhaps you are looking for value
?
Upvotes: 0