Hi,

I'm new to jQuery so I may miss something obvious...

I created a script that create/update a second select list when a
choice is made in the first one. Works fine in Firefox but only
partially in Explorer.

There is 2 problems:

On line:
    if ($("div#categories").length > 0) $("div#categories").empty();

it do resolve the condition but don't execute empty()

Same for replaceWith at the end of the script.

$(document).ready(function() {
        $("select#quantitesType").change(function() {
                var type = $(this).val();
                if (type == 0) {
                        if ($("div#categories").length > 0) 
$("div#categories").empty();
                } else {
                        var categories = <?php echo $categories ?>; // Json 
array
                        var selectDiv = $('<div>').attr('id', 
'categories').attr('class',
'input');
                        selectDiv.html('<label for="quantitesCategory"><?php
__('Catégorie') ?></label>');
                        var selectObj = $('<select>').attr('name', 
'data[quantites]
[category]').attr('id', 'quantitesCategory');
                        for (var i = 0; i < categories.length; i++) {
                                if (categories[i].quantite_type_id == type) {
                                        $('<option>').attr('value',
categories[i].id).text(categories[i].name).appendTo($(selectObj));
                                }
                        }
                        selectDiv.append(selectObj);
                        if ($("div#categories").length > 0) {
                                $("div#categories").replaceWith(selectDiv);
                        } else {
                                $("fieldset").append(selectDiv);
                        }

                }
        })
});
</script>

Reply via email to