Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.4 kB
1
Indexable
Never
$(document).ready(function () {
    scopeRadios = $('input[name="scope"]');
    categorySelect = $('#category');
    sourceSelect = $('#source');
    unitInput = $('#unit');
    unitInput2 = $('#unit2').hide(); // hide second input box by default
    carbonFactorInput = $('#carbonfactor');
    resultInput = $('#result');
    commentInput = $('#comment');
    charCount = $('#charCount');

    // Set initial state
    categorySelect.empty().append(new Option("Välj kategori", "", true, true)).prop('disabled', true);
    sourceSelect.empty().append(new Option("Välj källa", "", true, true)).prop('disabled', true);

    // trigger change event on page load to initialize state
    scopeRadios.change();
});

$('#clear').click(function() {
    $('input').val('');
    $('textarea').val('');
    $('#unit-label2').text('');
    $('#charCount').text('0/250');
    unitInput2.hide();
    unitInput.removeClass('col-4').addClass('col-8');
    $('.invalid-input').removeClass('invalid-input');

    // Clear radio button selection
    scopeRadios.parent().removeClass('active');
    scopeRadios.prop('checked', false).change(); // trigger change event
    
    // Reset category and source select elements
    categorySelect.empty().append(new Option("Välj kategori", "", true, true)).prop('disabled', true);
    sourceSelect.empty().append(new Option("Välj källa", "", true, true)).prop('disabled', true);
});