Are all the inputs produced by the loop intended to be submitted as part of one form? Why not collate them into an array?
Change the names from days
to days[]
and from date_now
to date_now[]
, respectively.
When embedding php control structures directly into html, consider using the alternative syntax for more clarity.
If you embed the current loop counter to the id of each input, you'll be able select each one individually.
If you add a class
attribute to each input, you can select them as a group.
You can eliminate the extra assignment to $ts
in each loop iteration by passing the result of strtotime()
directly to the second parameter of date()
.
Since it's not totally clear what your ultimate intent was, here is your initial code sample modified with all of my suggestions applied:
<?php
$date = date('m-d-Y');
$ts = strtotime($date);
$year = date('o', $ts);
$week = date('W', $ts);
for($i = 1; $i <= 7; $i++):
$dt = date("Y-m-d", strtotime($year.'W'.$week.$i));
?>
<td>
<input type="text" name="days[]" id="days<?=$i?>" class="days" />
<input type="hidden" name="date_now[]" id="date_now<?=$i>" value="<?=$dt?>" class="date_now" />
</td>
<?php endfor; ?>
From the above code, you can either select one of the inputs individually like this:
$("#days3").val();
Or, you can select all of the hidden inputs like this:
var dates_now = [];
$(".date_now").each(function(i, input) {
dates_now.push(input.val());
});