That did the trick Karl. Thanks for your help! :D
Rey
Karl Rudd wrote:
As far as I know you can't use anything but a simple number with the
":eq()" selector.
You could rewrite the code as:
$( "select#cert_id option:eq(" + (i > 1?1:0) + ")" ).attr(
"selected", true );
Note how the ternary operator is "outside" the selector string, it's
just used to produce a 1 or a 0, which is then merged into the
selector string.
Karl Rudd
On Tue, Apr 15, 2008 at 10:32 AM, Rey Bango <[EMAIL PROTECTED]> wrote:
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