I am trying to delete the value inside an input box based on a radio selection inside a table. The fact it is a table is where it is causing problems for me.
In the fun example I provided, I want to delete their favorite food if they say they don't like tacos on the radio buttons. This has been one of my attempts at trying to solve my issue, but it is not working or doing anything.
$(function() {
$
var $row = $(this).closest('tr')
$('.likesTacos').change(function() {
if (!$row.find(".likesTacos[value=['1']").is(":checked")) {
$row.find('.favFood').val("")
} else {
console.log("Good choice in food!")
}
})
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Favorite Food</th>
<th>Likes Tacos</th>
</tr>
<tr>
<td>Aaron</td>
<td>Rodgers</td>
<td><input textbox class="favFood" value="Tacos"></td>
<td>
<div>
<label><input type="radio" name="tacos1" class="likesTacos" value=1 />Yes</label>
</div>
<div>
<label><input type="radio" name="tacos1" class="likesTacos" value=0 />No</label>
</div>
</tr>
<tr>
<td>Brett</td>
<td>Favre</td>
<td><input textbox class="favFood" value="Tacos"></td>
<td>
<div>
<label><input type="radio" name="tacos2" class="likesTacos" value=1 />Yes</label>
</div>
<div>
<label><input type="radio" name="tacos2" class="likesTacos" value=0 />No</label>
</div>
</td>
</tr>
<tr>
<td>Bart</td>
<td>Starr</td>
<td><input textbox class="favFood" value="Tacos"></td>
<td>
<div>
<label><input type="radio" name="tacos3" class="likesTacos" value=1 />Yes</label>
</div>
<div>
<label><input type="radio" name="tacos3" class="likesTacos" value=0 />No</label>
</div>
</td>
</tr>
</table>