Advertisement
arizawan

Get all Inputs "Name" attribute in a html page

Jun 9th, 2020
706
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function myGetNameFunction() {
  2.   var x = document.getElementsByTagName("input");
  3.  
  4.   console.log("x: " + x);
  5.   console.log("Number of inputs: " + x.length);
  6.  
  7.   var arrayOfInputNames = [];
  8.  
  9.   for (var i = 0; i < x.length; i++) {
  10.     console.log("i: " + i);
  11.     console.log("value: " + x[i].name);
  12.     arrayOfInputNames.push(x[i].name);
  13.   }
  14.  
  15.   console.log(arrayOfInputNames);
  16. }
  17. myGetNameFunction();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement