Last active
March 26, 2022 23:14
-
-
Save vivascau/ff5e8eb972f8a301a2b6 to your computer and use it in GitHub Desktop.
Fill in visible inputs of type text or number on a page based on an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function fillForms(){ | |
var dataArr = ["REG_NUMBER","POST_CODE","REG_NUMBER","POST_CODE"], dataIndex = 0, i, | |
allInputs = document.getElementsByTagName("input"); | |
for(i=0; i<allInputs.length; i++){ | |
if(allInputs[i].style.display !== "none" && | |
(allInputs[i].type==="text" || allInputs[i].type==="number" || allInputs[i].type==="tel")){ | |
if(dataIndex >= dataArr.length){ | |
return; | |
} | |
allInputs[i].value=dataArr[dataIndex]; | |
dataIndex++; | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment