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..?
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..?
AFAIK, no element has a text property. Perhaps you are looking for value?
I think this is what you're after:
var sel = document.getElementsByName("FK_BrandID")[0];
var modelLength = sel.options[sel.selectedIndex].text;
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);
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;