How can I do this in Javascript/jQuery from PHP? I am trying to populate a select list from a start date up to 6 months in advance.
$startDate = intval( $c->getStartDate($pid) );
$endDate = strtotime('+6 month', $startDate);
$dateSelectList = '<select name="dateSelect" id="dateSelect">';
$count = 1;
//populates the select list with the starting date of the course up to the next six months
for($date = $startDate; $date <= $endDate ; $date = strtotime('+1 day', $date))
{
$dateSelectList .= '<option id="select'.$count.'" value="'.$date.'">'.date('D d F Y', $date).'</option>';
$count++;
}
$dateSelectList .= '</select>';
One way you can do this is to use ajax with jQuery. So first step is to modify your code to:
then save into a separate file say populate.php
Then on the html page you write the following code. Code assumes you have included jquery to your page and that you have a select element with id = dateSelect
The above code calls populate.php on load of the page, which returns all the options and injects it into the select element