Our eg. reads all dropdown lists from a table (id=tblTest)
(1) First read the object (table in our case) from which you need other objects.
var varTblTest = document.getElementById(‘tblTest’) ;
(2) Next you can find all the dropdown in the tblTest by the method, “getElementsByTagName”. The dropdown list renders as tag, “select”.
var varDdlsFromTable = varTblTest.getElementsByTagName(‘select’) ;
(3) Now varDdlsFromTable will have all the dropdownlists from the table in the form of array. You can loop through the array now to get individual object.
for(var i = 0 ; i < varDdlsFromTable.length ; i++)
{
alert(varDdlsFromTable[i].value) ; //gives the value of the ddl
alert(varDdlsFromTable[i][varDdlsFromTable[0].selectedIndex].text ; //gives the visible value of the ddl
}
Note: Instead of table it can be anything like, div, tr etc.
Write to me for any js related issues. Happy Coding