I have a select statement running which pulls data into $row.
$result = mysql_query("Select * FROM Recipes WHERE rID = $sent_rID");
$fields_num = mysql_num_fields($result);
$error = mysql_error($link);
$row = mysql_fetch_array($result);
Next I have my SELECT block
<select name='department' id='department'>
<option value='Deli'>Deli</option>
<option value='Meat'>Meat</option>
<option value='Seafood'>Seafood</option>
</select>
Finally I have the following SCRIPT block
<SCRIPT LANGUAGE='javascript'>
DepartmentSelect($row[rDepartment]);
</SCRIPT>
And here is DepartmentSelect()
<script type="text/javascript">
function DepartmentSelect(itemToSelect)
{
// Get a reference to the drop-down
var myDropdownList = document.inputForm.department;
// Loop through all the items
for (iLoop = 0; iLoop< myDropdownList.options.length; iLoop++)
{
if (myDropdownList.options[iLoop].value == itemToSelect)
{
// Item is found. Set its selected property, and exit the loop
myDropdownList.options[iLoop].selected = true;
break;
}
}
}
</script>
I have verified multiple times that all of the values are good, but for some reason the combobox refuses to show the right value. Any ideas?
Edit: The SCRIPT block occurs within a php echo, so it is pulling the correct value.
mysql_*functions in new code. They were removed from PHP 7.0.0 in 2015. Instead, use prepared statements via PDO or MySQLi. See Why shouldn't I use mysql_* functions in PHP? for more information.