Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.4 kB
2
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)).attr('disabled', true);
    sourceSelect.empty().append(new Option("Choose source", "", true, true)).attr('disabled', true);
    $('.invalid-input').removeClass('invalid-input');
});

sourceSelect.change(function () {
    unitInput.val('');
    unitInput2.val('').hide();
    unitInput.removeClass('col-4').addClass('col-8');
    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-8').addClass('col-4');
    } else {
        $('#unit-label2').text('');
    }
    carbonFactorInput.val(selectedData.carbonfactor);
});