Setting default values in a php dynamic list
whatalotofrubbish Dec 21, 2013 8:40 AMI have a drop down list that is populated by a recordset consisting of two fields, company (a text field shown in the drop down list) and company_ID (an integer key )
The default value for the field Company should be "unknown", and the form should not submit if the sleted value is "unknown"
The selection once made is used to insert the value into a new record, along with many others on the full form..
The code is complicated by the fact that it also includes some java script code from a check form behaviour, shown in orange for completeness.
How do I change the PHP code so that it shows the default value of "unknown" in the select box when run, instead of showing the last item in the companies list?
Should be simple enough, but I am too close to see the solution.
<td>
<select name="Companies_ID" size="1" class="contclass" id="Companies_ID" >
<%
while (!compny.EOF) {
%>
<option value="<%=(compny.Fields.Item("ID").Value)%>" <%=((compny.Fields.Item("ID").Value == (compny.Fields.Item("ID").unknown))?"SELECTED":"")%> <?php if (!(strcmp("<%=(compny.Fields.Item(\"ID\").Value)%>", $row_rsCompany['ID']))) {echo "selected=\"selected\"";} ?>><%=(compny.Fields.Item("company").Value)%></option>
<%
compny.MoveNext();
}
if (compny.CursorType > 0) {
if (!compny.BOF) compny.MoveFirst();
} else {
compny.Requery();
}
%>
<?php
do {
?>
<option value="<?php echo $row_rsCompany['ID']?>"<?php if (!(strcmp($row_rsCompany['ID'], $row_rsCompany['ID']))) {echo "selected=\"selected\"";} ?>><?php echo $row_rsCompany['company']?></option>
<?php
} while ($row_rsCompany = mysql_fetch_assoc($rsCompany));
$rows = mysql_num_rows($rsCompany);
if($rows > 0) {
mysql_data_seek($rsCompany, 0);
$row_rsCompany = mysql_fetch_assoc($rsCompany);
}
?>
</select>
<input name="company" type="hidden" id="company" value="<?php echo $row_rsCompany['company']; ?>" /></td>
<td>Select from list. If it does not exist, add a Company. </td>
mysql_data_seek($rsTypes, 0);
$row_rsTypes = mysql_fetch_assoc($rsTypes);
}
?>
</select>
<input name="company" type="hidden" id="company" value="<?php echo $row_rsCompany['company']; ?>" />



