tags:

views:

24

answers:

2

Hello i have a variable in jquery with the string "tuesday" in it, i also have a selectbox with all the days of the week in it, how can i assign my variable so that the selectbox automaticly selects my variable?

A: 
var yourselectvalue = 'tuesday';    
var selectobject=document.getElementById("yourselectboxid")

for (var i=0; i<selectobject.length; i++){
        if (selectobject.options[i].value == yourselectvalue) {
            selectobject.options[i].selected = true;
        }
    }
Alec Smart
+1  A: 

You can just use val():

​$('select').val("Tuesday");​​​​​​​​​​​​

Example: http://jsfiddle.net/EWVct/

Andy E