I am trying to create a general JS to
get the id and value from the input.
Then, put those into a JsonObject to pass back to the server.
The list is like this:
<ul id="myList" data-role="listview" data-inset="true">
<li> Field One <input id="Field_One" /></li>
<li> Field Two <input id="Field_Two" /></li>
<li> Field Three <input id="Field_Three" /></li>
<li> Field Four <input id="Field_Four" /></li>
</ul>
I could get the data for the listitem,
function Test(){
var unorderedList = document.getElementById('myList');
var ListItems = unorderedList.getElementsByTagName('li');
var listID
for (var i = 0; i < ListItems.length; i++) {
listID = ListItems[i].firstChild.data;
//alert(listID);
};
}
but I couldn’t go further to get the text ID or value.
(well, if i have id then i can get value…).
How do I get the input id/value in the ul/il with a loop?
No one is saying the
firstChildwill be the input. In fact, it’s most probably a text node.Give it a try:
Code Example