Jump to content

Change the SELECT value in drop down based off of a javascript variable value


dlebowski

Recommended Posts

I want to change the SELECT value based off of a javascript variable value.  For example, I want

 

var myvariable = NULL;

 

If myvariable = ONLINE do this:

 

<label class="solddropdown" style="display: none;">
<select id='onlineonsite' style="font-size: 10px;">
<option value="ONLINE" SELECTED >ONLINE</option>
<option value="ONSITE" >ONSITE</option>
</select>
</label>

 

else If myvariable = ONSITE do this:

 

<label class="solddropdown" style="display: none;">
<select id='onlineonsite' style="font-size: 10px;">
<option value="ONLINE" >ONLINE</option>
<option value="ONSITE" SELECTED >ONSITE</option>
</select>
</label>

 

Any help on this would be greatly appreciated!  Thank you.

You'll need to somehow identify each item in your list, probably by using id, then you'll need to (i'm assuming here) change the selected property from 'selected' to '' and vice versa, but that seems mad, so after a quick search...

 

http://www.mredkj.com/tutorials/tutorial002.html

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.