javascript - jQuery task, get the value of a select html element -



javascript - jQuery task, get the value of a select html element -

i have problem can't solve... have jquery code:

v=$('#sede').val(); $('#sede').change(function() { console.log('valor de v:'+v); });

and html select:

<select name="se" id="sede" size="1"> <option value="1">primer elemento</option> <option value="2">segundo elemento</option> <option value="3">tercer elemento</option> <option value="4">cuarto elemento</option> </select>

the problem variable v shows first item value when click in select, no matters second, 3rd or item...

you should value of <select> on alter event:

var v; $("#sede").change(function() { v = this.value; console.log("valor de v:" + v); });

javascript jquery html

Comments

Popular posts from this blog

javascript - mongodb won't find my schema method in nested container -

How do you set up a perforce server to work over the internet? -

ios - Lagging ScrollView with UIWebview inside -