emeralddragon Posted October 21, 2010 Share Posted October 21, 2010 Hi all, i need some help in retaining the values in an <option> textbox.. I have found a code to loop the date online, and use it for Javascript jump menu, but i have no ideas how to retain the option.. here are my codes(in red), $year1 = date('Y'); $month1 = date('m'); $day1 = date('j'); $day1 = $day1 + 1; $year2 = date('Y') + 2; $month2 = date('m'); $day2 = date('j'); $start_date = "$year1-$month1-$day1"; $end_date = "$year2-$month2-$day2"; $date = mktime(0,0,0,$month1,$day1,$year1); //Gets Unix timestamp START DATE $date1 = mktime(0,0,0,$month2,$day2,$year2); //Gets Unix timestamp END DATE $difference = $date1-$date; //Calcuates Difference $daysago = floor($difference /60/60/24); //Calculates Days Old $i = 0; while ($i <= $daysago +1) { if ($i != 0) { $date = $date + 86400; } else { $date = $date - 86400; } $yy1 = date('Y',$date); $mm1 = date('m',$date); $dd1 = date('d',$date); $date3 = "$yy1-$mm1-$dd1" ; echo "<option value=\"test1234.php?m=$mm1&y=$yy1&d=$dd1\" "; echo ">".$date3 ."</option>"; $i++; } i know that i have to something selected, but i dun understand how this set of date code loop which left me helpless. Quote Link to comment Share on other sites More sharing options...
Buddski Posted October 21, 2010 Share Posted October 21, 2010 If I understand correctly you can check the url variables and compare them to the date values in the loop Here is a dodgy example echo "<option ".($_GET['m'] == $mm1 && $_GET['y'] == $yy1 && $_GET['d'] == $dd1 ? 'selected="selected"' : '')." value=\"test1234.php?m=$mm1&y=$yy1&d=$dd1\" "; Quote Link to comment Share on other sites More sharing options...
emeralddragon Posted October 21, 2010 Author Share Posted October 21, 2010 Thks pal, It works!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.