Skip to content

Instantly share code, notes, and snippets.

@avostryakov
Created April 3, 2010 12:00
Show Gist options
  • Save avostryakov/354423 to your computer and use it in GitHub Desktop.
Save avostryakov/354423 to your computer and use it in GitHub Desktop.
sizes = new Array({{ product_sizes|safe }});
function filterSizeSelectField()
{
product_type = $("#id_product_type").val();
fields = $("select[id*='-size']").serializeArray();
size_options = '<option value="">---------</option>';
$.each(sizes,
function(i, size)
{
if (size['product_type'] == product_type || size['product_type'] == null )
{
size_options += '<option value="' + size['id'] + '">' + size['name'] + '</option>';
}
})
$("select[id*='-size']").html(size_options);
$.each(fields,
function(i, field)
{
name = "#id_" + field.name
$(name).val(field.value);
if ($(name).val() == null)
{
$(name).val("")
}
});
}
$("#id_product_type").change(filterSizeSelectField);
filterSizeSelectField();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment