I have a table with input from Flask, and some fields of the table have input boxes for the user. I am trying to get the value of what they input and I am struggling. I figure this is an easy question for people here, but I have been banging my head against my desk for a while now and searched the forums here without figuring out what I'm doing wrong.
I created a similar but much simpler HTML table to what I have for us to play around with. I have not been able to get to the radio button part yet because I'm still trying to get the input box part solved, but I will be needing to get both of those. Ideally, I'd be returning each row into a JSON array.
The JQuery I included returns "Cannot read property 'GetElementsByTagName' of undefined", but it's only one of the many examples I've tried without any success. I've tested variations with .value, .text, .innerHTML, but I just can't get what's inside the box (or the radio button value for that matter).
Any help for a JS novice?
//$('.tableRow').each(function() {
// favoriteBeer = document.getElementsByClassName('favoriteBeer').document.GetElementsByTagName('input');
// console.log(favoriteBeer);
//});
table {
border-collapse: collapse;
}
table,
th,
td {
border: 1px solid black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="myTable">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Favorite Food</th>
<th>Favorite Beer</th>
</tr>
</thead>
<tbody>
<tr class='tableRow'>
<td>John</td>
<td>30</td>
<td><label><input type="radio" name="favoriteFood1" value="Pizza"/>Pizza</label><label><input type="radio" name="favoriteFood1" value="Tacos" />Tacos</label>
<td><input type="text" class="favoriteBeer"></td>
</tr>
<tr class='tableRow'>
<td>Joe</td>
<td>25</td>
<td><label><input type="radio" name="favoriteFood2" value="Pizza"/>Pizza</label><label><input type="radio" name="favoriteFood2" value="Tacos"/>Tacos</label>
<td><input type="text" class="favoriteBeer"></td>
</tr>
<tr class='tableRow'>
<td>Sam</td>
<td>50</td>
<td><label><input type="radio" name="favoriteFood3" value="Pizza"/>Pizza</label><label><input type="radio" name="favoriteFood3" value="Tacos"/>Tacos</label>
<td><input type="text" class="favoriteBeer"></td>
</tr>
</tbody>
</table>