...

View Full Version : Help in selected drop-down list doesn't show



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.

technica
10-26-2009, 10:38 AM
Have you thought of using sessions to store the selected values. So that next time when the page refreshes the values from session are checked for the drop down box.

Also while refreshing are you doing post back to the server? in that case you may read the drop down values selected prior to refreshing the page and check these values against the values in drop down.

abduraooft
10-26-2009, 11:56 AM
Write an if condition to check the value in th posted data against the value from your foreach loop and add an attribute like selected="selected" for the matched one..

jmarian1
10-26-2009, 08:37 PM
Have you thought of using sessions to store the selected values. So that next time when the page refreshes the values from session are checked for the drop down box.

Also while refreshing are you doing post back to the server? in that case you may read the drop down values selected prior to refreshing the page and check these values against the values in drop down.

Hi technica, thanks for your help. Yes, I did try SESSION and POST but both still doesn't work. and the worst is, instead of the first array that will show when it is a new page, it shows the last number which is the 12. I don't understand why it is giving me this problem knowing that my other form is working just fine with the same data. Is there any suggestions? Thanks.

jmarian1
10-26-2009, 08:41 PM
Hi abduraooft, thanks for your suggestion. I actually use the if condition and use
selected="selected" but it shows the last number only and it didn't change at all. Although it is capturing the number to my server which is giving me the right selection, I wanted to show it to the user what they selected but it doesn't work. Please help! I am desperate to make this work. Thanks.

abduraooft
10-27-2009, 07:50 AM
That attribute has to be applied on the required <option> tag and not on the <select> tag

jmarian1
11-04-2009, 01:17 AM
Thanks a lot for your help abduraooft but it really doesn't work. I tried to include the
selected="selected" in the
but still didn't work. Please help I need to make this work tomorrow. Thanks in advance.

jmarian1
11-04-2009, 02:01 AM
Is there any other way to do it instead of using PHP? I guess it is better if I use regular HMTL but it will be long, can somebody please advice? I need to make this work by tomorrow and I am really behind as I am spending lots of time just to make this problem work. Please help!!!!! Thanks.

shadowmaniac
11-04-2009, 03:42 AM
<?php echo helper_selected($year == $form['expiry_year']); ?>

Is that even a valid argument for helper_selected?

Please try:


<?php echo helper_selected($form['expiry_year']); ?>


If that doesn't work, make sure you're returning a $form array with the selected month and year when an "error" has been found, in whichever php file you're using to validate and process the form.

jmarian1
11-11-2009, 10:06 PM
HI. Sorry to reply this late. I actually never make it to work but will try again next time. If I come out with a solution I will post it here. Thanks for all your help.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum