Reputation: 71
My box is populating from my database but I would like to show the drop down box blank until it is clicked to select. Not quite sure how to do that. Thanks in advance
<select type="text" name='id' id="inputItem" placeholder="Item #1" class="form-control">
<?php
require ('dbconnect.php');
$result = $con->query("select id, item from items");
while ($row = $result->fetch_assoc()) {
unset($id, $name);
$id = $row['id'];
$name = $row['item'];
echo '<option value="'.$id.'">'.$name.'</option>';
}
echo "</select>";
mysqli_close($con);
?>
</div>
Upvotes: 0
Views: 74
Reputation: 510
Before your while loop:
echo '<option value="">--- Select ---</option>';
Upvotes: 0
Reputation: 18600
<select type="text" name='id' id="inputItem" placeholder="Item #1" class="form-control">
<option value=''>Select First</option>
Upvotes: 0
Reputation: 100175
you could add blank option before while
loop, as:
...
echo '<option value="">Select</option>';
while ($row = $result->fetch_assoc()) {
unset($id, $name);
$id = $row['id'];
$name = $row['item'];
echo '<option value="'.$id.'">'.$name.'</option>';
}
...
Upvotes: 0
Reputation: 5428
Add <option>Choose One...</option>
immediately after your first line.
Upvotes: 1