Created
October 29, 2021 15:58
-
-
Save davidverhage/4c26b3e370c7368300cee449113d8f47 to your computer and use it in GitHub Desktop.
Proud to be lazy Form namer
This file contains hidden or 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
/* | |
* Doemela | PROJECT070 | |
* Clean function to use id as name for form inputs | |
*/ | |
function setNameAttribute(){ | |
var inputs = document.getElementById("deathnotice").elements; | |
// Iterate over the form controls | |
for (let i = 0; i < inputs.length; i++) { | |
// for the current found input collect the input ID | |
let id = inputs[i].id; | |
// set the name attribute to id | |
inputs[i].setAttribute("name", id); | |
// check if you did not mess up... :) | |
console.log(inputs[i], 'input id', id); //remove this line when going live | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment