Generate a select structure dynamically with PHP, something like this:
<?
$OptionValue[0] = "something 1";
$OptionValue[1] = "something 2";
$OptionValue[2] = "something 3";
$Option[0] = "List Option 1";
$Option[1] = "List Option 2";
$Option[2] = "List Option 3";
function GenerateSelect ($Name, $OptionValue, $Option, $SelectedValue) {
/*
The Select function writes an HTML SELECT statement.
$OptionValue = array with option values
$Option = array with the option wording in the pull down
menu
$SelectedValue = the option value that is currently selected
by the user
*/
echo "<SELECT name='".$Name."' SIZE='1'>";
for ($i = 0; $i <= count($OptionValue) - 1; $i++) {
if ($SelectedValue != "" && $OptionValue[$i] ==
$SelectedValue) {
echo "<OPTION VALUE='".$OptionValue[$i]."'
SELECTED>".$Option[$i]."</OPTION>";
} else {
echo "<OPTION
VALUE='".$OptionValue[$i]."'>".$Option[$i]."</OPTION>";
}
}
echo "</SELECT>";
return 0;
}
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="test.php">
</form>
</body>
</html>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="">
<?
echo "You chose ".$MyList."<br>";
GenerateSelect ("MyList", $OptionValue, $Option, $MyList)
?>
<br>
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
Regards
Rudolf Visagie
Principal Software Developer
Digital Healthcare Solutions
<mailto:[EMAIL PROTECTED]>
Tel: 011 2655478
Cell: 082 895 1598
-----Original Message-----
From: Steve Fitzgerald [mailto:[EMAIL PROTECTED]]
Sent: Monday, July 08, 2002 1:36 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Session variables
I am designing a form using sessions in which the user inputs their
details on page 1 and after submitting they are directed to page 2 for
confirmation. They then have the option of editing their input (ie they
are returned to page 1) where their previous input is reflected in the
form fields by
value ='<?php echo $var ?>'
This works fine except if the input type is a drop down box, in which
case the default <option> is shown. Is there any way around this? How
can I show the user their previous choice in these boxes?
Any insights would be appreciated.
Steve
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php