Im making a selectbox with the values from my DB, and I want the first value to be “make a choice”.
How can it be done?
I have this code..
<tr>
<td width="180" height="30"><label for="valgtkon" class="labelLeft">Vælg konkurrencetype</label></td>
<td><select id="valgtTitel" name="valgtTitel" onchange="run()">
<?php
$virksomhedsID = $_SESSION['virkID'];
$sql = "SELECT * FROM konkurrenceType ORDER BY konkurrenceType.kontypeID";
$result = mysql_query($sql) or die(mysql_error());
while($rowSelect = mysql_fetch_assoc($result))
{
$kontypeTitel = $rowSelect['kontypeTitel'];
$kontypeID = $rowSelect['kontypeID'];
echo '<option value="' . $kontypeID . '">' . $kontypeTitel . '</option>';
}?>
</select></td>
<script>
function run() {
document.getElementById("valgtID").value = document.getElementById("valgtTitel").value;
}
</script>
<td><input type="text" name="valgtID" id="valgtID"/></td>
</tr>
Before the while loop, add another echo statement creating the option for the first “make a choice” option, then add some validation on submission to make sure they selected a different choice from the list.