Forums

PHP

This topic is locked

select from drop down using a cookie

Posted 22 May 2011 21:07:47
1
has voted
22 May 2011 21:07:47 Chris Trace posted:
Hey there,

i have a cookie which echos ok but would like to know how to automatically select the corresponding option from a drop down list when the page loads.

Normal List

<form id="switchform">
<select name="switchcontrol" size="1" class="topusernav" onChange="chooseStyle(this.options[this.selectedIndex].value, 60)">
<option value="none">-----</option>
<option value="noir">Noir</option>
<option value="crimson">Crimson</option>
<option value="forrest">Forrest</option>
<option value="ocean">Ocean</option>
<option value="petal">Petal</option>
</select>
</form>

works fine

but

<form id="switchform">
<select name="switchcontrol" size="1" class="topusernav" onChange="chooseStyle(this.options[this.selectedIndex].value, 60)">
<option value="none" <?php if (!(strcmp("none", "$_COOKIE[\"mysheet\"];")) {echo "selected=\"selected\"";} ?>>-----</option>
<option value="noir" <?php if (!(strcmp("noir", "$_COOKIE[\"mysheet\"];")) {echo "selected=\"selected\"";} ?>>Noir</option>
<option value="crimson" <?php if (!(strcmp("crimson", "$_COOKIE[\"mysheet\"];")) {echo "selected=\"selected\"";} ?>>Crimson</option>
<option value="forrest" <?php if (!(strcmp("forrest", "$_COOKIE[\"mysheet\"];")) {echo "selected=\"selected\"";} ?>>Forrest</option>
<option value="ocean" <?php if (!(strcmp("ocean", "$_COOKIE[\"mysheet\"];")) {echo "selected=\"selected\"";} ?>>Ocean</option>
<option value="petal" <?php if (!(strcmp("petal", "$_COOKIE[\"mysheet\"];")) {echo "selected=\"selected\"";} ?>>Petal</option>
</select>
</form>

gives me a whitespace error

any thoughts??

thanks

Reply to this topic