Jump to content

Option retaining values in text box Help!!


emeralddragon

Recommended Posts

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.

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\"  ";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.