0

Hey,

I have a combo box and want to populate it with the selected value upon page reload. For a normal text field I would usually do something like this:

<input type="text" name="title" value="<?php echo $_SESSION['sellform']['title']; ?>">

How could I do the same for a drop-down box? E.g:

<select name="condition">						
					<option value="">--Condition--</option>
					<option value="new">New</option>
					<option value="used">Used</option>
</select>

Edited by nonshatter: n/a

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by whiteyoh
0

if the items are stored in dbase you could use while
something like

<?php 
***** GET THE RECORDs
echo "<option> $value </option>";
0

What if the data is hardcoded? Basically the user specifies their product details, then clicks submit, the form data is then posted back to itself on the same page to be validated (server-side). If errors are detected, then I want the fields to be re-populated with the users session data... Simples?

My attempt:

<td>Condition:</td>
<td><select name="condition" <?php echo htmlentities($values['condition']) ?>>						
	<option value="">--Condition--</option>
	<option value="new">New</option>
         <option value="used">Used</option>
        <option value=""><?php echo $_SESSION['sellform']['condition']?></option>
</td>

I've got it working for all input fields except for drop-down boxes.

Thanks in advance

0

if your posting back to yourself you i would suggest putting it all in a form

eg......

<?php
if (isset($_POST['submit'])){
$product = $_POST['product'];
if ($product ==""){
echo "something missing";
}
}
?>
<form method="post" action=<?php $_SERVER[PHP_SELF];?>
form stuff and all your options etc
</form>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.