TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-13-2009, 02:16 AM   #1 (permalink)
The Acquainted
 
Dave's Avatar
 
Join Date: Apr 2008
Posts: 110
Thanks: 97
Dave is on a distinguished road
Default 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 is offline  
Reply With Quote
Old 09-13-2009, 04:20 AM   #2 (permalink)
The Acquainted
 
Dave's Avatar
 
Join Date: Apr 2008
Posts: 110
Thanks: 97
Dave is on a distinguished road
Default

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
Dave is offline  
Reply With Quote
Old 09-14-2009, 08:40 PM   #3 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,298
Thanks: 17
Village Idiot is on a distinguished road
Default

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.
__________________

Village Idiot is offline  
Reply With Quote
The Following User Says Thank You to Village Idiot For This Useful Post:
Dave (09-15-2009)
Old 09-15-2009, 03:52 AM   #4 (permalink)
The Acquainted
 
Dave's Avatar
 
Join Date: Apr 2008
Posts: 110
Thanks: 97
Dave is on a distinguished road
Default

Thanks! This is good to learn.

Let me ask, why would the form differences be ignored? Is it for the sake of faster reloading?
Dave is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Form Validation Not Working :( Guezala Absolute Beginners 27 05-13-2009 08:28 PM
PHP fill in form help sacred_tinker Absolute Beginners 6 10-08-2008 12:28 PM
email fill in form help? PHP sacred_tinker Absolute Beginners 19 05-28-2008 05:58 AM
working with Iframes in php JMHein Absolute Beginners 3 05-17-2008 03:40 PM
Starting with php in my html page Shinoken Absolute Beginners 5 01-08-2008 01:34 PM


All times are GMT. The time now is 10:46 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design