You are here: Re: Saving selection in drop-down lists in PHP after page reload? « PHP Programming Language « IT news, forums, messages
Re: Saving selection in drop-down lists in PHP after page reload?

Posted by Geoff Berrow on 06/19/06 23:59

Message-ID: <1150760275.219250.264370@u72g2000cwu.googlegroups.com> from
dshan@web.de contained the following:

>The PHP script returns, e.g., an "AL" string for Alabama. Of course, I
>don't want to write PHP code for each option to make it selected.


The way I do it requires some setup, but you only do it once,
First you create an array of states and codes

e.g.

$states= array("AL"=>"Alabama","TX"=>"Texas","VA", "Virginia",...);

then use PHP to create your select box

Untested.

<select name='state'>
<?php
foreach($states as $key=>$value){
if(isset($_POST[$key]) &&$_POST[$key]==$value){
$selected="selected";
}
else{
$selected="";
}
echo"<option value='$key' $selected >$value</option>\n";

}
?>


</select>


--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация