Selecting values from a multiselect not working in webkit

Posted by azz0r on Stack Overflow See other posts from Stack Overflow or by azz0r
Published on 2010-05-28T08:55:08Z Indexed on 2010/05/30 9:52 UTC
Read the original article Hit count: 368

Filed under:
|

Hello!

The code below works fine in Firefox. However in Chrome and Safari it doesn't.

Essentially it returns an array of values, then selects them from multiselect. However in Chrome and safari it doesn't select the items from the multiselect.

    $('form#movie select#movie_movie').click(function(){
    var id = $(this).val();
    $("#movie_category option:selected").attr('selected', '');
    $("#movie_model option:selected").attr('selected', '');
    $("#movie_gallery option:selected").attr('selected', '');
    $("#movie_playlist option:selected").attr('selected', '');

    if (id != 0) {
        $.ajax({
            type: 'POST',
            url: "/administration/link/movie/id/"+id,
            dataType: 'json',
             beforeSend: function(x) {
                $.blockUI({theme: true, title: 'Loading', message: '<p>Please wait...</p>', timeout: 1000});
                if(x && x.overrideMimeType) {
                    x.overrideMimeType("application/json;charset=UTF-8");
                }
             },
            error: function() {
                $.unblockUI();
                alert('Error loading object, please try again');
            },
            success: function(returned_values) {
                 $.unblockUI();
                 $.each(returned_values.object.playlist || {}, function(i, item) {$("#movie_playlist option[value='"+item+"']").attr('selected', 'selected');});
                 $.each(returned_values.object.category || {}, function(i, item) {$("#movie_category option[value='"+item+"']").attr('selected', 'selected');});
                 $.each(returned_values.object.model || {}, function(i, item) {$("#movie_model option[value='"+item+"']").attr('selected', 'selected');});
                 $.each(returned_values.object.gallery || {}, function(i, item) {$("#movie_gallery option[value='"+item+"']").attr('selected', 'selected');});

            }
        });
    }
});

So the part that isn't working in them is:

$("#movie_playlist option[value='"+item+"']").attr('selected', 'selected');

Any ideas??

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about multiselect