Guys,
I wanted to set an option in a select element to "selected". The options
are being created on the fly. The rules are simple. If there's more than
one option, then set the second option to "selected". Otherwise, set the
first option to "selected". I tried to use a ternary operator but it failed:
$("select#cert_id option:eq((i > 1?1:0))").attr( "selected", "selected" );
If I use the code below, it works:
if (i > 1) {
$("select#cert_id option:eq(1)").attr( "selected", "selected" );
}
else {
$("select#cert_id option:eq(0)").attr( "selected", "selected" );
}
Could someone give me some insight as to why the ternary expression
option failed?
Thanks,
Rey