Since I am calling this code in loop. But following code is giving me error as document.getElementsById is not a function. What should I do how can I call doc.getbyid in loop.
for (var z=1; z < i; z++){
var textbox = document.getElementsById("a"+z).value;
var textbox2 = document.getElementsById("b").value;
var textbox3 = document.getElementsById("c").value;
alert(textbox);
alert(textbox2);
alert(textbox3);
}
That's because it getElementById (note the lack of the "s" on "Element"). Which makes sense if you think about it, because id values have to be unique in a document, so there will be only one "element" that matches, rather than multiple "elements".
However, there are methods that return multiple elements which do use the plural "elements", such as getElementsByTagName, so you may just be mixing them up.
The function is not getElementsById but getElementById.
There is no plural form on Element
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