[UPHPU] dynamically selecting an option

Wade Preston Shearer wadeshearer.lists at me.com
Fri Sep 25 18:16:59 MDT 2009


In case someone else needs to do this, I'll share something I just  
learned (read: wasted a bunch of time on):

If you want to dynamically select an option within a select element,  
the following won't work (using jQuery):

$('option').attr('selected', 'selected');


You have to use selectedIndex on the select, like this:

$('select').get(0).selectedIndex = value;


It's interesting that the first option doesn't work since this does:

$('input').attr('disabled', 'disabled');
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2431 bytes
Desc: not available
Url : http://uphpu.org/pipermail/uphpu/attachments/20090925/a1128001/attachment.bin 


More information about the UPHPU mailing list