I’m am attempting to get the value of one input in a table row IF one of the other cells in the row has a value. The goal here is, if the user entered money received into the row, then a received date is required. So, on submit I want to look through all the rows and check for an entry in the current cell, then check for a date in the date cell. There are more than one row for payment entry. Here is the HTML:
<div class="new_payments">
<tr>
<td>
<input type="text"
name="new_payments[<?php echo $s ?>][payment_date]"
class="payment_date"
size='10' maxlength="10"
>
</td>
<td>
<input type="text"
name="new_payments[<?php echo $s ?>][credit_card]"
class="credit_received"
size="8">
</td>
<td>
<input type="text"
name="new_payments[<?php echo $s ?>][check]"
class="check_received"
size="8">
</td>
<td>
<input type="text"
name="new_payments[<?php echo $s ?>][cash]"
class="cash_received"
size="8">
</td>
</tr>
</div>
Here is the jQuery I am using (haven’t added the check for a value in ‘this’ yet) to see if I am getting the expected result. Sadly, I’m getting ‘undefined’:
jQuery('input:text.cash_received').each (function() {
var $theDate = jQuery(this).closest('div.new_payments').find('.payment_date').attr('value');
alert('the closest date value is ' + $theDate );
});
I thought I understood the concept of go up to the parent then find the element you’re looking for. Apparently not? Thanks for your excellent help!
this is tested and working. it will only alert if
.cash_receivedhas a value. i added values to the inputs for testing. also note the removal of the div wrapper. i added the class to the TR