Forum Moderators: coopster
Now my question is, As far a drop downs go, is there a way to make the option that is already stored in the database for the current client show up as the initially selected item in the dropdown?
Example: Administrator clicks to edit a client, and they get to the form page there is a dropdown that says: Active Client? with the answers Yes and No. If No is already stored in the DB how can I make sure that is the initially selected item in the dropdown. Same goes for 'Yes' if that is the value already stored in the DB.
Am I making any sense.
Thanks for any help,
Russell
<form>
<select size="1" name="form[active]">
<option value="1" <?php
if ($is_active) echo 'selected="selected"';
?>>YES</option>
<option value="0"<?php
if (!$is_active) echo 'selected="selected"';
?>>NO</option>
</select>
Andreas
If you're not working with session vars the procedure is the same. Like this if you have only a few options:
<select>
<option value="1" <?if (isset($dbvalue) && $dbvalue == "1") {?>SELECTED<?}?>>1</option>
<option value="2" <?if (isset($dbvalue) && $dbvalue == "2") {?>SELECTED<?}?>>1</option>
</select>
If you have a longer list loading from the db it goes like this, assuming you have all values in an array:
<select>
for ($i = 0; $i < count($dbarray);$i++) {
<option value="<? echo $dbarray[$i]?>" <?if (isset($dbvalue) && $dbvalue == $dbarray[$i]{?>SELECTED<?}?>><? echo $dbarray[$i]?></option>
}
</select>
$dbvalue of course is the value you load from your database.
I hope this helped,
greets, Stefan
can i do this:
<form>
<select size="1" name="form[active]">
<option value="1"
<?php
if ($active == 1) {
echo 'selected="selected"';
?>
>Active</option>
<option value="0"
<?php
if ($active == 2)
echo 'selected="selected"';
?>
>Inactive</option>
<option value="0"
<?php
if ($active == 3)
echo 'selected="selected"';
?>
>Completed</option>
</select>
anyone know if that will work?
Greets,Stefan
There's no need to "echo 'selected="selected"'
unless you want your HTML code to be XHTML compliant: XML does not support attribute minimization [w3.org].
Instead 'echo "SELECTED"' is sufficient
unless you want your HTML code to be XHTML compliant: All element and attribute names must be lower case [w3.org].
can i do this:
If you remove the opening brace in if ($active == 1) { then that code will work. You might want to use values for the value attribute that correspond to the content in each option element.
Andreas