0

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.

2

2 Answers 2

1

You need to add quotes.

Your code would output:

DepartmentSelect(Deli)

Rather do this:

<SCRIPT LANGUAGE='javascript'>
DepartmentSelect('<?=$row["rDepartment"];?>');
</SCRIPT>
Sign up to request clarification or add additional context in comments.

1 Comment

Worked! Everything was in an echo block already, but throwing apostrophe's around $row[rDepartment] made all the difference.
0

try:

<SCRIPT LANGUAGE='javascript'>
DepartmentSelect(<?php echo $row[rDepartment]; ?>);
</SCRIPT>

or:

<SCRIPT LANGUAGE='javascript'>
DepartmentSelect(<?php echo $row["rDepartment"]; ?>);
</SCRIPT>

1 Comment

Ah sorry, I should have added that this the script block occurs within a php echo, so it is pulling the correct value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.