I am struggling to create a function that will auto-fill a number of boxes with the value inputted into the first box on the button click (if there is way of doing this without a button click I would love to hear about it!). I wanted to use class for this to save me using each element ID. However, I am not doing this correctly. If someone could help with this I would be really grateful (I am new to programming and I am not sure what I’m doing).autofill.hype.zip (9.9 KB)
Hei Simon,
you´re on the right way, using classes is a good idea…
var inputvalue = document.getElementById('inputbox1').innerHTML; // get value of first textfield
var boxesArr = document.querySelectorAll ('.autofillbox'); // get all textfields with class 'autofillbox and write it to an array
// fill boxes
for (i=0;i<boxesArr.length;i++){
var myBox = boxesArr[i];
myBox.innerHTML = inputvalue;
}