Re: [PHP] Drop down list - persistant value

2005-04-13 Thread Peter H. Lemieux
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.=\nselect name=\$fieldname\ $opt ;
foreach ($options as $key=$val) {
$output.=\noption 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 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Drop down list - persistant value

2005-03-21 Thread Jacques
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 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Drop down list - persistant value

2005-03-21 Thread Burhan Khalid
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?
Set the attribute selected on the country, ie :
option value=12 selected=selectedUnited States/option
This is really a HTML question, not PHP related.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php