TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   PHP-html select form not working as hoped...? (http://www.talkphp.com/absolute-beginners/4942-php-html-select-form-not-working-hoped.html)

Dave 09-13-2009 02:16 AM

PHP-html select form not working as hoped...?
 
Good evening, everyone --

The following code is supposed to generate an html select form with a dropdown list of months, with the CURRENT MONTH pre-selected.

The dropdown list works, but the current month is not pre-selected as the default.

I've spent a lot of time on this, but have been unsuccessful. Thanks for taking a look!

-- Dave

PHP Code:

$arr_month = array(  =>  "January" 
                   
=>  "February"
                   
=>  "March"
                   
=>  "April"
                   
=>  "May"
                   
=>  "June"
                   
=>  "July"
                   
=>  "August"
                   
=>  "September"
                   
10 => "October"
                   
11 => "November"
                   
12 => "December"
                  
) ;

$today date"M-d-y"time() ) ;
echo 
"<div style = 'text-align: center'>\n" ;
echo 
"<h3>Today is $today</h3><hr>\n" ;

// create form containing date selection list 

echo "<form action = 'processform.php'
            method = 'POST'>\n" 
;

$todaymo date"n"time() ) ;

echo 
$todaymo "<br />" ;

echo 
"<label for 'datemo'></label>
      <select name = 'datemo' id = 'datemo'> \n" 

      
for ( 
$n $n <= 12 $n++ )
{
    echo 
"<option value = $n;
    if ( 
$todaymo == $n )
    {
        echo 
" selected" ;
    }
    echo 
"> $arr_month[$n] \n" ;
}
echo 
"</select>" 


Dave 09-13-2009 04:20 AM

Ahh...actually, I think it is working, at least when the page loads from scratch.

If I then select a month from the dropdown list and refresh the browser (not total reload), the month designation is not returned to the selected month -- it just stays at whatever state I left it.

Aww, nice...how come? I thought refreshing completely re-ran the code.

Thanks again.

Dave

Village Idiot 09-14-2009 08:40 PM

It does, but most browsers will ignore form differences when a page is refreshed. What you can do is have javascript select the current month when the page loads.

Dave 09-15-2009 03:52 AM

Thanks! This is good to learn. ^^

Let me ask, why would the form differences be ignored? Is it for the sake of faster reloading? :-!


All times are GMT. The time now is 11:39 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0