Problem when setting a value to a dropdown in jQuery
I have this strange problem in JQuery. I try to set a value to a dropdown dinamically, so I have this code:
$('#activity').val(idValue);
//or this way:
$('#activity').val("'"+idValue+"'");
but it does not work. However, if I'm setting the value "statically" then it works:
$('#activity').val('23');
So, why does not accept the value from the variable? Or what am I doing wrong? Thanks!
UPDATE
I have tried the code in jsfiddle and it does work. It seems that the problem was related to the JSON data i was parsing. Thanks for the help!开发者_如何学编程
What do you get if you alert idValue?
Alternatively, I would also try attr().
$('#activity').attr('value',idValue);
idValue may be a number type, try
$('#activity').val(idValue.toString());
精彩评论