views:

133

answers:

1

I have the following jQuery code which runs when I'm clicking an option in a select box:

$('#name, #account, #kid')
    .attr('disabled', 'disabled')
    .css('background-color', '#ffffcc')
    .animate({ backgroundColor:'#ffffff' }, 1000);

This code takes the three input fields #name, #account and #kid, disables them, change background-color and then fades background-color to white. I am using the jQuery Color plugin that allows me to fade colors.

The problem is, that when a site is freshly loaded, and I'm changing the select's selected option, it disables all three fields, changes background-color and, but the first element #name won't fade background-color to white. Only the two following.

But if I try to change the select box option again, it works perfectly, every time! So the problem is only occurs the first time after a page reload. Anybody else experienced the same before?

Here's the jQuery in it's whole:

$('#receiver').change(function(){

    var selected = $(this).children('option:selected').val();

    if (selected == 'new')
    {
        $('#name, #account, #kid').val('').attr('disabled', '');
    }
    else
    {
        $.getJSON("<?php echo site_url('ajax/get_receivers') ?>",
        function(data){
            $.each(data, function(i, data){
                if (data.id == selected)
                {
                    $('#name').val(data.name);
                    $('#account').val(data.account);
                    $('#kid').val(data.kid);

                    $('#name, #account, #kid')
                        .attr('disabled', 'disabled')
                        .css('background-color', '#ffffcc')
                        .animate({ backgroundColor:'#ffffff' }, 1000);
                }
            });
        });
    }

});

#receiver being the select box.

+1  A: 

Both WFM with ajax/json request

http://jsbin.com/egani --> with jQuery UI

http://jsbin.com/ekura/ --> with old jQuery color plugin (2years+)

jitter
I actually managed to get the same error with yours: http://cld.ly/8baxb
rebellion
This might be platform/browser specific. WFM on WinXP SP3 Opera 10.01, IE6, FF 3.5.4. What do you use?
jitter
I'm on Safari 4.0.3/Mac. I've tested with Firefox 3.5.3/Mac too, where the third field actually hung up once, and the second field hung up once with Google Chrome 4.0.223.11 (development preview) for Mac.Not tested on Windows yet.
rebellion
check expanded answer
jitter
Didn't do anything. I don't think I'll bother trying to fix it. Maybe I can find another plugin which works :P
rebellion
Btw just noticed that jQuery UI supports this. Guess that's why the original jquery color plugin wasn't developed further (probably code merged into jQuery UI). Can you try the sample I made with jQuery UI instead of the old plugin
jitter