Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.9 kB
1
Indexable
Never
$('#clear').click(function() {
    $('input').val('');
    $('textarea').val('');
    $('#unit-label2').text('');
    $('#charCount').text('0/250');
    unitInput2.hide();
    unitInput.removeClass('col-4').addClass('col-8');
    $('input[name="scope"]').prop('checked', false);
    categorySelect.empty().append(new Option("Choose category", "", true, true)).prop('disabled', true);
    sourceSelect.empty().append(new Option("Choose source", "", true, true)).prop('disabled', true);
    $('.invalid-input').removeClass('invalid-input');
    scopeRadios.prop('checked', false); // Clear radio button selection
});

scopeRadios.change(function () {
    categorySelect.empty();
    categorySelect.append(new Option("Choose category", "", true, true)).prop('disabled', false);
    let selectedScope = $(this).val();
    let categories = [...new Set(data.filter(item => item.scope == selectedScope).map(item => item.category))];
    categories.forEach(category => {
        categorySelect.append(new Option(category, category));
    });
});

sourceSelect.change(function () {
    unitInput.val('');
    unitInput2.val('').hide();
    unitInput.removeClass('col-4').addClass('col-6');
    let selectedScope = $('input[name="scope"]:checked').val();
    let selectedCategory = categorySelect.val();
    let selectedSource = $(this).val();
    let selectedData = data.find(item => item.scope == selectedScope && item.category == selectedCategory && item.source == selectedSource);
    let units = selectedData.unit.split(";");
    $('#unit-label').text('Input (' + units[0] + ')');
    unitInput.show();
    if (units.length > 1) {
        $('#unit-label2').text('Input (' + units[1] + ')');
        unitInput2.show();
        unitInput.removeClass('col-6').addClass('col-4');
    } else {
        $('#unit-label2').text('');
    }
    carbonFactorInput.val(selectedData.carbonfactor);
});