The reason why this didn't work:

$('#courses optgroup:eq("+choosenValue+") option');

Is that you are mixing single quotes and double quotes.

$('#courses optgroup:eq('+choosenValue+') option');

Would work, if choosenValue is a variable that has the value of 3.

JK


-----Original Message-----
From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of mjpg
Sent: Monday, March 03, 2008 8:35 AM
To: jQuery (English)
Subject: [jQuery] :eq() expects number problem


I'm selecting an item based on using an index.
:eq(3) works but if I pass a variable it does not.

CODE SNIPPET:

function populateSelect(choosenValue) {
     // Get the optgroup options
     var choosenOptions = $('#courses optgroup:eq(choosenValue)
option');
     ....

THE FOLLOWING WORKS:

$('#courses optgroup:eq(3) option');

DO NOT SEEM TO WORK:

$('#courses optgroup:eq("+choosenValue+") option');     // and I don't
understand this anyhow

or
choosenValue = parseInt(choosenValue);
$('#courses optgroup:eq(choosenValue) option');

or
choosenValue = Number(choosenValue);
$('#courses optgroup:eq(choosenValue) option');


I'd appreciate a pointer here. I can see :eq expects a number and I'm
struggling to deleiver it.

Thanks


Reply via email to