jmarian1
10-26-2009, 10:24 AM
Hi. Please help with my code. I have a drop down list selected using an array to select the month and year for expiration date. The problem is, when I select the month and year and some fields has error, the page refresh but the selection I made for the month is gone and it goes back to the default which is the first selected Index as "--". Below is my array as it is written:
global $expiry_month;
$expiry_month = array(
"" => "--",
"01" => "01",
"02" => "02",
"03" => "03",
"04" => "04",
"05" => "05",
"06" => "06",
"07" => "07",
"08" => "08",
"09" => "09",
"10" => "10",
"11" => "11",
"12" => "12",
);
global $expiry_year;
$expiry_year = array(
"" => "--",
"09" => "09",
"10" => "10",
"11" => "11",
"12" => "12",
"13" => "13",
"14" => "14",
"15" => "15",
"16" => "16",
"17" => "17",
"18" => "18",
"19" => "19",
"20" => "20",
);
Here is my form code for the expiration date:
<select id="expiry_month" name="expiry_month" style="width:50px;">
<?php foreach ($expiry_month as $monthselect => $month) : ?>
<option value="<?php echo $monthselect; ?>" <?php echo helper_selected($monthselect == $form['expiry_month']); ?>><?php safeEcho($month); ?></option>
<?php endforeach; ?>
</select>
<select name="expiry_year" id="expiry_year" style="width:50px;" onChange="expiredate() ;" selected='' >
<?php foreach($expiry_year as $year =>$prompt) : ?>
<option value = "<?php echo $year; ?>"
<?php echo helper_selected($year == $form['expiry_year']); ?>
>
<?php safeEcho($prompt); ?>
</option>
<?php endforeach;?>
</select>
I want if possible to show what I selected originally when the page refresh for any error on the other page like for example if I selected 12 for month and 10 for year I wanted to show the 12 10 when the page refresh but it doesn't. What did i do wrong with this? I spent almost how many days to figure out but I couldn't. Please, I really need to make this work as soon as possible. Please help!!!! Thanks in advance.
global $expiry_month;
$expiry_month = array(
"" => "--",
"01" => "01",
"02" => "02",
"03" => "03",
"04" => "04",
"05" => "05",
"06" => "06",
"07" => "07",
"08" => "08",
"09" => "09",
"10" => "10",
"11" => "11",
"12" => "12",
);
global $expiry_year;
$expiry_year = array(
"" => "--",
"09" => "09",
"10" => "10",
"11" => "11",
"12" => "12",
"13" => "13",
"14" => "14",
"15" => "15",
"16" => "16",
"17" => "17",
"18" => "18",
"19" => "19",
"20" => "20",
);
Here is my form code for the expiration date:
<select id="expiry_month" name="expiry_month" style="width:50px;">
<?php foreach ($expiry_month as $monthselect => $month) : ?>
<option value="<?php echo $monthselect; ?>" <?php echo helper_selected($monthselect == $form['expiry_month']); ?>><?php safeEcho($month); ?></option>
<?php endforeach; ?>
</select>
<select name="expiry_year" id="expiry_year" style="width:50px;" onChange="expiredate() ;" selected='' >
<?php foreach($expiry_year as $year =>$prompt) : ?>
<option value = "<?php echo $year; ?>"
<?php echo helper_selected($year == $form['expiry_year']); ?>
>
<?php safeEcho($prompt); ?>
</option>
<?php endforeach;?>
</select>
I want if possible to show what I selected originally when the page refresh for any error on the other page like for example if I selected 12 for month and 10 for year I wanted to show the 12 10 when the page refresh but it doesn't. What did i do wrong with this? I spent almost how many days to figure out but I couldn't. Please, I really need to make this work as soon as possible. Please help!!!! Thanks in advance.