I want to create a list of all the names of a form's elements. however with the following code I got the error: "inputs.map is not a function"
I am aware the inputs
is not an array, however I am not sure about how to get a this .map
to function ?
function process(form) {
console.dir(form)
var inputs = form.elements
for (let i = 0; i < inputs.length; i++) {
console.log(i+':'+inputs[i].name+': '+inputs[i].value);
}
let names = inputs.map( e => e.name )
console.log(names)
}
<form name=form1 method=none>
firstname: <input name=lastn value="a" type=text>
<br>lastname: <input name=firstn value="b" type=text>
<br>zipcode: <input name=zip value="c" type=text>
<br>ip: <input name=ip value="127.0.0.1" type=text disabled>
<br><input onclick="process(this.parentNode)" name=button type=button value="register">
</form>
btw to run the code you have to click the "register" button (as it is an "onclick" call)