Please register or login. There are 0 registered and 1377 anonymous users currently online. Current bandwidth usage: 326.30 kbit/s December 17 - 10:36am EST 
Hardware Analysis
      
Forums Product Prices
  Contents 
 
 

  Latest Topics 
 

More >>
 

    
 
 

  You Are Here: 
 
/ Forums / Programming /
 

  PHP Select drop down box 
 
 Author 
 Date Written 
 Tools 
jeremy scharlow May 04, 2013, 02:37pm EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List Replies: 2 - Views: 1233
Hello,

I have created a drop down box and when I submit it i want the selected item to remain selected in the drop down box instead of going back to the first option in the drop down box.

below is my code:

<?php

$selmonths = array(1=>'January', 'February, 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'

echo "<form method='post' action=' '>";

echo "<select name='months' >";
foreach ($selmonths as $i=>$opt ):
echo "<option value='$i'>$opt</option>";
endforeach;
echo "</select>";

echo "<input type =submit value=Submit>";

?>

Any help would be appreciated.


Want to enjoy fewer advertisements and more features? Click here to become a Hardware Analysis registered user.
jeremy scharlow May 04, 2013, 02:40pm EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List  
>> Re: PHP Select drop down box
I just realized in my post i forgot to close my array and put the end line in. its there in my original code and the drop down works. It just always goes back to the first option once selected instead of staying on the selected item.

Afrow UK May 05, 2013, 07:47am EDT Reply - Quote - Report Abuse
Private Message - Add to Buddy List  
>> Re: PHP Select drop down box
You have to explicitly add selected="selected" to the <option> that you want to select, depending on the submitted value (in $_POST). This goes for check boxes and radio buttons too (checked="checked").

Stu

I like: Programming, Gym, University
Music: House, Dubstep, D&B, Trance, Metal

Write a Reply >>


 

    
 
 

  Topic Tools 
 
RSS UpdatesRSS Updates
 

  Related Articles 
 
 

  Newsletter 
 
A weekly newsletter featuring an editorial and a roundup of the latest articles, news and other interesting topics.

Please enter your email address below and click Subscribe.