Autofill boxes using a user input value

Hello everyone!

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) (9.9 KB)

Many thanks in advance!


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;

Hope, this helps, regards
Kalle (16.0 KB)


That is fantastic! Thank you for solving my problem so quickly!!

1 Like