What is the best way to retrieve the value of the name
attribute using JavaScript?
HTML :
<input class="so" name="Name" value="bob"></input>
<input class="so" name="LastName" value="Feyzi"></input>
<input class="so" name="Email"></input>
<input class="so" name="Address"></input>
<input type="submit"></input>
JavaScript :
var person={};
var cars = document.querySelectorAll(".so");
for (i = 0; i < cars.length; i++) {
var elname = document.getElementByClassName('.so')[i].getAttribute('name');
//var eln = document.getElementsByTagName("input")[i].getAttribute("name");
var vala= document.querySelectorAll('.so')[i].value;
//alert(vala);
alert(elname);
}
Once I execute the script, I expect the person
object to be updated with this information:
person {
Name: "bob",
LastName: "Feyzi",
Email: "",
Adderss: ""
}