I have a repeating table where the name of the elements would be (e.g. 'tdName_1' 'tdName_2'), and I was wondering if it would be possible to getElementsByName('tdName_').
PS: I can not use Jquery.
Thanks In advance.
Cesar.
The difference is that GetElementByID() will retrieve a single element object based on the unique id specified, whereas GetElementsByTagName() will retrieve an array of all element objects with the specified tag name. Then you can obtain the value using GetElementById from your C++ code.
The getElementsByName() method of the Document object returns a NodeList Collection of elements with a given name attribute in the document.
JavaScript getElementsByName() example How it works: First, select the submit button by its id btnRate using the getElementById() method. Second, listen to the click event of the submit button. Third, get all the radio buttons using the getElementsByName() and show the selected value in the output element.
This is not possible. I'm assuming for the rest of this answer that the elements you're interested in are <td>
s. If so, then you should be aware that the name
attribute is not valid for <td>
elements.
You will have to create a list of matching elements manually. If you decide to use the name
attribute anyway (instead of, say, adding a class in the class
attribute), something like the following will work:
var table = document.getElementById("your_table_id");
var tds = table.getElementsByTagName("td");
var matchingTds = [];
for (var i = 0, len = tds.length, td, tdName; i < len; ++i) {
td = tds[i];
tdName = td.getAttribute("name");
if (tdName && tdName.indexOf("tdName_") == 0) {
matchingTds.push(td);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With