I need to retrieve the values of each input tag that is within a named div tag.
Thank You
I need to retrieve the values of each input tag that is within a named div tag.
Thank You
What is the code you have so far?
If you put them within a form tag then it’s much easier to loop through the elements in that form.
<form id="exampleFormIdentifier">
<p><input name="somefield"></p>
<p><input name="anotherfield"></p>
...
</form>
in JavaScript, forms have an elements collection that makes it easy for you to access named elements within them.
var form = document.querySelector('exampleFormIdentifier'),
elements = form.elements,
i;
for (i = 0; i < elements.length; i += 1) {
// do stuff with elements[i] here
}
...
// or if you want to access just a single field
var fieldValue = form.elements.anotherfield.value;
var named = document.getElementById("named-div");
var tags = named.getElementsByTagName("input");
for (var i = 0, n = tags.length; i < n; i = i + 1) {
console.log(tags[i].value);
}