I am dynamically creating a table and want to capture the keypress event on the dynamically created date textboxes. If I have only one payment_date textkbox it's great, but I have many. I've looked at .live but I'm too new at this to figure it out. Can someone be specific for me please? Here is the HTML with the textbox in question:
<?php
foreach($student_classes as $class):
if( $student['student_id'] == $class['student_id'] ) {
$i = $class['registration_id'];
$deleted = FALSE;
?>
<td>
<input type="text"
name="students[<?php echo $i ?>][registration_payment_date]"
id="payment_date[<?php echo $i ?>]"
value="<?= html($class['registration_payment_date']) ?>"
size='10' maxlength="10"
>
</td>
<?php endforeach; ?>
jQuery:
jQuery(document).ready(function ()
{
var $payment_date = jQuery('#payment_date');
// Format the date as it is entered
$payment_date.keypress(function(event) {
DateFormat(this, this.value, event, false, '1');
});
// Check to make sure the date is valid
$payment_date.change(function ()
{
if( dateValid(this.value) == false );
alert('The date is not valid');
});
});
Thank you!