Welcome Guest, Not a member yet? Register   Sign In
Need Advice with Dynamic Drop Down Menu
#1

[eluser]vincej[/eluser]
Hi - I have a drop down menu which dynamically presents dates. See code below.

Code:
echo form_open('admin/reports/SpecificLocationDate');
foreach ($deliverydates as $series => $data) {
       $TheDates  = explode(',', $data['TheDates']);
  }

$options = array(
$TheDates['0']=>strftime("%a %d %b %Y", $TheDates['0']),
$TheDates['1']=>strftime("%a %d %b %Y", $TheDates['1']),
$TheDates['2']=>strftime("%a %d %b %Y", $TheDates['2']),
$TheDates['3']=>strftime("%a %d %b %Y", $TheDates['3'])
);

echo "Filter by Delivery Date:   ";
echo form_dropdown('locations',$options,'all');
echo form_hidden('locationid',$data['locationid']);
echo "&nbsp;&nbsp;&nbsp;".form_submit('submit','Submit')."</span><br><br><br>";
echo form_close();

OK - The user can select a delivery date to filter the future orders. It all works excellently so long as the dates are in the future. If the user is a bit slow in maintaining the delivery dates and accidentally allows one of them to slip into the past, then the query that fills the drop down with future dates, causes one or more of the drop down options being empty. This causes a nasty "Undefined index:" error. What is more strftime() reacts to the empty index by filling it in with Dec 31 1969.

So, I need advice on how I can manage this situation when the user lets a date go into history. I had thought of perhaps using a switch statement to provide multiple different sets of drop down options. But that feels very messy. Of course I cou;d just change the initial query to allow historical dates to be presented - but that feels amaturish.

Any Advice is gratefully received,

MANY THANKS !
#2

[eluser]vincej[/eluser]
I have come up with an ingenious idea for solving my problem above, but I am not sure how to do it in CI.

It's simple really, I allow my query to pass all dates ie historical and future. This means I will not get any more empty index's and no more errors.

But, if the date is in the past i.e. < Time() then I apply text-color: white to the offending date. It's still there, but to the user, it looks like a blank option.

So, I probably can do it in Javascript / Jquery, but I would rather avoid that.

Any ideas how to apply a conditional style to a Select Option ??

Many Many thanks !




Theme © iAndrew 2016 - Forum software by © MyBB