I've made a nice little function to return a NodeList
array containing all the inputs that have a specified name attribute:
function GiveElementsByName(name) {
var finalOutput = [], times = document.getElementsByTagName('input').length, inOutput = 0, inAll = 0; //For use later.
while(times--)
{
if (document.getElementsByTagName('input')[inAll].name == name) //Apply to all inputs with specified name.
{
finalOutput[inOutput] = document.getElementsByTagName('input')[inAll]; //Array with all the matching inputs.
inOutput++;
}
inAll++;
}
return finalOutput;
}
function MyFunc() {
GiveElementsByName("Lol1")[1].value = "I don't like potatos anymore";
}
<input type="text" name="Lol1" value="I like potatos">
<input type="text" name="Lol1" value="I like potatos">
<input type="text" name="Lol1" value="I like potatos">
<input type="text" name="Lol1" value="I like potatos">
<br><br><br><br>
<input type="text" name="Lol2" value="I like potatos more">
<input type="text" name="Lol2" value="I like potatos more">
<input type="text" name="Lol2" value="I like potatos more">
<input type="text" name="Lol2" value="I like potatos more">
<br><br><br><br>
<input type="button" value="Click me!" onClick="MyFunc()">
Could you help me shrink down the function and make it quicker?