+ Start a Discussion
Yashita Goyal 12Yashita Goyal 12 

Get Selected option value of rows in a table getting created dynamically having class name of select option

Am getting issue in retrieving selected select option value in lightning controller. The table rows are craeted dynamically assigning class name select option table cell.
Below is the code am using in lightning controller:
var tableId = document.getElementById("myTable");
var rowCount = tableId.rows.length;
var e = document.getElementsByClassName("slds-select");
for (var i = 0; i < rowCount; i++){
	var tempo = e[i].options[e[i].selectedIndex];
	var selOperator = tempo.value;
	console.log('selOperator: '+selOperator);

However am able to get output on console but with error on screen:

Console Output and Error on Screen

Any help will be appreciated.

Did you try using console.log() statements to see if you are actually finding your components using  document.getElementById()? This may not work as you think. Also, it would be a better approach if you actually do this natively in Lightning Components. Try to make the rows of your table components and let them decide if they are selected or not. 

One of the things that I like the best about LC, is that Salesforce has brought OOP to the web development!
Yashita Goyal 12Yashita Goyal 12
1. I can see my component is loading by using document.getElementByClassName() --> innerHTML
2. I can't use document.getElementById() as am creating rows dynamically and am only setting class name. So, I need solution which uses document.getElementByClassName()
You need to use the features of Lightning Components as I answered in my previous post
Yashita Goyal 12Yashita Goyal 12
Got it resolved . It was issue in my table row cell loop.

Thanks :)