Skip to content

Instantly share code, notes, and snippets.

@davidverhage
Created October 29, 2021 15:58
Show Gist options
  • Save davidverhage/4c26b3e370c7368300cee449113d8f47 to your computer and use it in GitHub Desktop.
Save davidverhage/4c26b3e370c7368300cee449113d8f47 to your computer and use it in GitHub Desktop.
Proud to be lazy Form namer
/*
* 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