Created
October 29, 2021 15:58
Proud to be lazy Form namer
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
/* | |
* 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