RE: 'Code Snippets' you couldn't live without

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Another code snippet I use quite regularly builds a form select list from a
delimited string.

function displayFormSelect($selvals, $selname, $val=''){
	$optval = explode(",", $selvals);
	$retval = "<select name='$selname'>";
	foreach ($optval as $key => $value){
		$retval .= "<option value='".$value."'";
		if ($value == $val)
			$retval .= " selected";
		$retval .= ">".$value."</option>";
		
	}
	$retval .= "</select>";
	return $retval; 
}

Basically, I use it like so:

$optstring = 'Option 1,Option 2,Option 3';
$optname = 'frmoptions';
$optsel = 'Option 3';

$formsel = displayFormSelect($optstring, $optname, $optse);

echo $formsel;

The optional third value defines the option that appears 'selected' if
provided.

Looking at it, it would be pretty easy to change this to pass a recordset
array to it etc.

Much warmth,

Murray
http://www.planetthoughtful.org
Building a thoughtful planet,
One quirky comment at a time.

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux