I'm trying to generate a select box through php. Simple no problems there.
However, the problem comes when I try to dynamically add in the 'selected' attribute to one of the options.
My script is basically the following:
foreach($values as $key => $value) {
if ($key == $checkVar) { $selected = ' SELECTED'; } else { $selected = ''; }
$options .= '<option value="'.$key.'"'.$selected.'>'.$value.'</option>';
}
print '<select>'.$options.'</select>';
Goes through an array of values and if it matches the right one, addes the 'selected' attribute.
However, when I run this, it doesnt select the right option.
The thing that REALLY drives me nuts is that if I copy the direct source code that was generated from php into dreamweaver and preview it... it selects the option just fine.
I'm fresh out of ideas... anyone?