Just as an aside, related to a recent thread entitled 'Performance tip' (
http://groups.google.com/group/jquery-en/browse_thread/thread/15a11a44b29c27b2/d8bfffd73b4ebb9f#d8bfffd73b4ebb9f)
please, please, please for everyone's sanity don't do
$(...).children().size() in the body of a for loop, it's bad for your
health!

Cache the return value and use that otherwise every iteration results in
calling the children() and size() functions just to obtain the same value:

var count = $("#smsUserPrice").children().size();
for (var i=0; i < count; i++)
{ ... }


jQuery also provides a much cleaner way to iterate through a collection,
$.each().
And to answer your question, use the javascript boolean value true, not the
string "true".
My final version of your code is this:

$("#smsUserPrice option").each(function()
{
   // $(this) is the current <option> element
   var value = $(this).val();

   if (value == eventObjects[clickedObject.attr
('id')].find('Price').text())
      $(this).attr("selected", true);
}


Hope that all helps,
--rob

On 5/24/07, Gordon <[EMAIL PROTECTED]> wrote:


Try "selected" instead of "true"

On May 24, 1:00 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> my code looks like this:
>
> for(var i=0; i<$("#smsUserPrice").children().size(); i++){
>                                                         curSmsOption =
$("#smsUserPrice").find("option:eq("+i+")");
>
>
if($(curSmsOption).attr("value") ==
> eventObjects[clickedObject.attr('id')].find('Price').text()){
>
$(curSmsOption).attr("selected", "true");
>                                                         }
>                                                 }




--
Rob Desbois
Eml: [EMAIL PROTECTED]
Tel: 01452 760631
Mob: 07946 705987
"There's a whale there's a whale there's a whale fish" he cried, and the
whale was in full view.
...Then ooh welcome. Ahhh. Ooh mug welcome.

Reply via email to