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. Link to comment https://forums.phpfreaks.com/topic/216466-option-retaining-values-in-text-box-help/ 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\" "; Link to comment https://forums.phpfreaks.com/topic/216466-option-retaining-values-in-text-box-help/#findComment-1124810 Share on other sites More sharing options...
emeralddragon Posted October 21, 2010 Author Share Posted October 21, 2010 Thks pal, It works!!! Link to comment https://forums.phpfreaks.com/topic/216466-option-retaining-values-in-text-box-help/#findComment-1124812 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.