PDA

View Full Version : Passing a default value


villardk
04-01-2006, 07:13 PM
Need help in trying to figure out how to pass a default value from one php page to another php page with a dropdown value. I want to have the customer select a link based on a choice of options and go to a customization page where their choice is now the default value in a dropdown menu. They can then leave it as is or change it.

Thanks.

Daryl

Kakao
04-01-2006, 08:07 PM
First page:

<html>
<head>
</head>
<body>
<p><a href="custom.php?color=red">red</a></p>
<p><a href="custom.php?color=green">green</a></p>
<p><a href="custom.php?color=blue">blue</a></p>
</body>
</html>

<?php
$color = $_GET['color'];
?>
<html>
<body>
<select>
<option value="red" <?php echo $color == "red" ? 'selected' : '' ?>>red
</option>
<option value="green" <?php echo $color == "green" ? 'selected' : '' ?>>green
</option>
<option value="blue" <?php echo $color == "blue" ? 'selected' : '' ?>>blue
</option>
</select>
</body>
</html>

Programming Crash Course (http://programming-crash-course.com/)

crocodile
04-02-2006, 03:43 AM
<?php
//tips of selected by www.z4.cn
$clr = $_GET['color'];
if($clr) {
$sl[$clr] = " selected=\"selected\"";
}
else {
$sl['red'] = " selected=\"selected\"";
}
?>
<html>
<body>
<form action="" method="get">
<select name="color">
<option value="red"<?=$sl['red']?>>red</option>
<option value="green"<?=$sl['green']?>>green</option>
<option value="blue"<?=$sl['blue']?>>blue</option>
</select>
</form>
</body>
</html>

villardk
04-03-2006, 05:05 PM
Thanks for the help. This is just what we were looking for.:)