You are here: Re: [PHP] Drop down list - persistant value « PHP « IT news, forums, messages
Re: [PHP] Drop down list - persistant value

Posted by Peter H. Lemieux on 11/10/39 11:13

I use a function to create select boxes:

function make_select($fieldname,$options,$selected,$opt="") {

# make a select box with option text $opt
# $fieldname = name of html field
# $options = associative array of select options
# $selected = field key of selected item
# $opt = optional attributes, e.g., styles, etc.

$output.="\n<select name=\"$fieldname\" $opt >";

foreach ($options as $key=>$val) {

$output.="\n<option value=\"$key\"";
if ($key==$selected) {
$output.=" selected";
}
$output.=">$val";
}

$output.="\n</select>\n";
return $output;

}

By passing the previously selected item as $selected it will
automatically reselect the chosen item. For instance,

<?php echo make_select("myfield",$options,$_POST["myfield"]) ?>


I've written similar functions for check boxes and radio buttons.
They've made form creation and handling enormously easier.

Peter


Jacques wrote:
> I am using PHP. I have a registration page where the user has to select his
> country form a drop down list. If the username that the user selected for
> himself exists in the database I am sending him back to the registration
> form with all the fields completed with the values he previously entered.
> This is easy to do for a textfield but how do I indicate on the drop down
> list which country he originally selected?
>
> Please help.
>
> Jacques
>

 

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

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