Creating drop downs on add screen
Posted: Wed Nov 17, 2010 9:56 am
I have a page where the user is adding a new record. On the table I will be inserting there are several fields in that table that the user selects data from supporting tables to add the record. When the page first opens I want these drop down fields to be BLANK, not filled with the first value in the table they willl be selecting from. Here is my code and I don't understand why it is displaying the first value instead of blank.
Any help in this matter is appreciated.
Thanks
Code: Select all
<form name='workorder' method='post' action='' >
<table border='1' cellspacing="1" style="width: 65%" >
<tr><td><strong>WO Number:*</strong></td>
<td>
<input type='text' name='wo_num' value='<?php echo $wo_num; ?>' size='8' />
</td>
</tr>
<tr>
<td><strong>Customer:*</strong></td>
<td><select name="wo_cust_id">
<?php
$cquery = 'SELECT cust_id, cust_nm FROM customer where cust_status = "A" ORDER BY cust_nm';
$cresult = mysql_query($cquery, $conn);
while($crow = mysql_fetch_array($cresult, MYSQL_ASSOC))
{
$ccust = $crow['cust_id'];
$cnm = $crow['cust_nm'];
if ($_POST['wo_cust_id'] == $ccust)
{
print("<option value='' selected='selected'>$cnm</option>"); - [b]trying to display blank instead of first field[/b] }
else
{
print ("<option value='$ccust'>$cnm</option>");
}
}
?>
</select>
</td></tr>
<tr>
<td><strong>Start Date:</strong></td>
<td>
<input type='text' id='wo_start_dt' name='wo_start_dt' value='<?php echo $wo_start_dt; ?>' />
<a href="javascript:NewCssCal('wo_start_dt','yyyymmdd','arrow',false,24,true)"><img src="images/cal.gif"
width="16" height="16" alt="Pick a date"></a></td></tr>
<tr>
<td><strong>Completion Date:</strong></td>
<td>
<input type='text' id='wo_cmpl_dt' name='wo_cmpl_dt' value='<?php echo $wo_cmpl_dt; ?>' />
<a href="javascript:NewCssCal('wo_cmpl_dt','yyyymmdd','arrow',false,24,true)"><img src="images/cal.gif"
width="16" height="16" alt="Pick a date"></a></td></tr>
<tr>
<td><strong>Inspector:*</strong></td>
<td><select name="wo_insp_id">
<?php
$iquery = 'SELECT insp_id, insp_nm FROM inspector where insp_status = "A" ORDER BY insp_nm';
$iresult = mysql_query($iquery, $conn);
while($irow = mysql_fetch_array($iresult, MYSQL_ASSOC))
{
$insp = $irow['insp_id'];
$inm = $irow['insp_nm'];
if($_POST['wo_insp_id'] == $insp)
{
print("<option value='' selected='selected'>$inm</option>"); [b]trying to display blank instead of first field[/b]
}
else
{
print ("<option value='$insp'>$inm</option>");
}
}
?>
</select>
</td></tr>
<tr>
<td><strong>Job:*</strong></td>
<td><select name="wo_job_id">
<?php
$jquery = 'SELECT job_id,job_num,job_nm FROM jobs ORDER BY job_nm, job_num';
$jresult = mysql_query($jquery, $conn);
while($jrow = mysql_fetch_array($jresult, MYSQL_ASSOC))
{
$jobs = $jrow['job_id'];
$jnm = $jrow['job_nm'] . " - " . $jrow['job_num'];
if($_POST['wo_job_id'] == $jobs)
{
print("<option value='' selected='selected'>$jnm</option>"); [b]trying to display blank instead of first field[/b]
}
else
{
print ("<option value='$jobs'>$jnm</option>");
}
}
?>
</select>
</td></tr>
<tr>
<td><strong>Short Description:*</strong></td>
<td>
<input type='text' name='wo_shrt_desc' value='<?php echo $wo_shrt_desc; ?>' size='50' />
</td></tr>
<tr>
<td><strong>Job Description:</strong></td>
<td>
<textarea name='wo_job_desc' rows='5' cols='40'><?php echo $wo_job_desc; ?></textarea> </td>
</tr>
<tr>
<td><b>Status:</b></td>
<td><select name='wo_status'>
<option value=''>Select...</option>
<option value='Active' <?php if ($wo_status == 'Active'): ?>selected='selected'<?php endif; ?>>Active</option>
<option value='Scheduled' <?php if ($wo_status == 'Scheduled'): ?>selected='selected'<?php endif; ?>>Scheduled</option>
<option value='Complete' <?php if ($wo_status == 'Complete'): ?>selected='selected'<?php endif; ?>>Complete</option>
</select></td></tr>
<tr>
<td colspan='2' align='center'>
<input type='submit' name='Submit' value='Update'/>
</td>
</tr>
</table>
</form>
Thanks