JSFiddle - React, Tailwind, and code Playground
by Dave Mednick
HTML
<form>
<table>
<tr id="">
<td width='5%'>
<label>Row 1 :</label>
</td>
<td width='10%'>
<input type='text' class="required" name="text1" />
</td>
</tr>
<tr id="">
<td width='5%'>
<label>Row 2 :</label>
</td>
<td width='10%'>
<input type='text' class="required" name="text2" />
</td>
</tr>
<tr id="">
<td width='5%'>
<label>Row 3 :</label>
</td>
<td width='10%'>
<input type='text' class="required" name="text3" />
</td>
</tr>
<tr id="">
<td width='5%'>
<label>Row 4 :</label>
</td>
<td width='10%'>
<input type='text' class="required" name="text4" />
</td>
</tr>
</table>
<tr>
<td colspan="2">
<input type="button" id="btnSubmit" value="Submit" />
</td>
</tr>
</form>
JavaScript
$(function () {
$('#btnSubmit').click(function () {
var requireds = $(':text.required');
requireds.each(function (i) {
if ($(this).val() === "") {
var label = $(this).closest('tr').find('label').text();
alert(label + 'is empty!');
}
});
});
});