Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Client Side Scripting
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 09-22-2005, 01:32 PM
  #1
mrjonman
Novice (Level 1)
 
Join Date: Sep 2005
Location: Cleveland, Ohio USA
Posts: 2
iTrader: (0)
mrjonman is an unknown quantity at this point
How Can I Programmatically Set Defaults for HTML Menus?

Hello all

I'm new to this forum. Please forgive me if the answer to this question is archived here - I couldn't find anything.

I hope I'm calling these items (html menus) by their correct name. I'm talking about the dropdowns created in html with <select></select> tags.

I'm developing a tracking program that connects to a mySQL database for my own use. In it I have a number of html menus used to select beginning and ending dates for different screens. I want the dropdowns to "remember" the last setting I selected before submitting the form.

I can write a value to the database to store default values but I'm not sure how to programmatically add "selected" to the menu's code to cause a certain value to be displayed the next time the page is displayed. Is there another way to set the default value for an html menu?

I hope I'm being clear enough. Any help would be greatly appreciated.

Thanks

John
mrjonman is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 09-22-2005, 01:52 PM
  #2
jonirvine
Paladin (Level 15)
 
jonirvine's Avatar
 
Join Date: Oct 2000
Location: York, UK
Posts: 337
iTrader: (0)
jonirvine is on a distinguished road
Hi John,

I'm not sure I'm completely understanding you, but it sounds like you have a date inside a drop down menu and when editing it, it doesn't show the date previously selected.....

If this is the case.....

1) STEP 1 - Extract data from mySQL database

Extract all the data, as you would, normally from the database.

2) SPLIT date value

PHP Code:
list($THISyear,$THISmonth,$THISday) = explode('-',$THISrow['date']); 
You now have values for the dates year, month and day in the variables above.

3) Show drop downs.

Now you have the values you need to create the drop downs and make sure if the current day is equal to that above it is selected.. and the same for month and year.

So, for day:

PHP Code:
    echo '<select name="day">'."\n";
    
$STARTday 1;
    while (
$STARTday <= 31) {
        echo 
'<option value="'.$STARTday.'"';
        if(
$STARTday==$THISday) { echo ' selected="selected" ';}
        echo 
'>'.$STARTday.'</option>'."\n";
        
$STARTday++;
    }
    echo 
'</select>'."\n"
For Month:

PHP Code:
        echo '<select name="month">'."\n";
            echo 
'<option value="01"';
                if(
$THISmonth==01) {echo ' selected="selected" ';}
            echo 
'>January</option>'."\n";
            echo 
'<option value="01"';
                if(
$THISmonth==02) {echo ' selected="selected" ';}
            echo 
'>February</option>'."\n";
            
//............ etc...............
        
echo "</select> "
for year:

PHP Code:
        $STARTyear 2000$ENDyear date("Y")+10;
        echo 
'<select name="year">'."\n";
            while (
$STARTyear <= $ENDyear) {
                echo 
'<option value="'.$STARTyear.'"';
                if(
$STARTyear==$THISyear) {echo ' selected="selected"';}
                echo 
'>'.$STARTyear.'</option>'."\n";
                
$STARTyear++;
            }
        echo 
'</select>'."\n"
Hope this makes sense and is what you're looking for.... i rushed it a little.

Jon

Last edited by jonirvine : 09-22-2005 at 01:54 PM.
jonirvine is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 09-24-2005, 01:07 PM
  #3
mrjonman
Novice (Level 1)
 
Join Date: Sep 2005
Location: Cleveland, Ohio USA
Posts: 2
iTrader: (0)
mrjonman is an unknown quantity at this point
Hi Jon

Thanks, it's exactly what I was looking for!

I do have one other problem with my webpage. I have a form with a submit button. I would like to know when the submit button has been clicked (versus refreshing the page)

I would think this has to be a simple php technique that as a complete php newb, I'm just not aware of.

Any suggestions would be appreciated.

Thank you

John

Last edited by mrjonman : 09-24-2005 at 02:37 PM.
mrjonman is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart
 
 


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



 
  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
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 03:00 AM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.