Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Convert Jquery to Vanilla Script

Is it possible to rewrite the following code into pure javascript? I don’t want to use jquery.

$(function () {
    var aggregateInput = function () {
        var value = ('Website Url: ') + jQuery('input[name="url"]').val() + ' \n  \n' +
            ('Subject: ') + jQuery('input[name="subject"] \n').val() + ' \n  \n' +
            ('Brief Message: ') + jQuery('textarea[name="customer service"] \n  \n').val().replace(/\n/g, '<br/>');
        jQuery('textarea[name="email-message"]').val(value);
    }
    jQuery('.contact-style').on('keyup', aggregateInput);
});

$(document).ready(function () {
    $('.contact-form-button-submit').attr('disabled', true);
    $('.customform-message').keyup(function () {
        if ($(this).val().length != 0) {
            $('.contact-form-button-submit').attr('disabled', false);
        } else {
            $('.contact-form-button-submit').attr('disabled', true);
        }
    })
});

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

document.addEventListener('DOMContentLoaded', function () {
    var aggregateInput = function () {
        var value = ('Website Url: ') + document.querySelector('input[name="url"]').value + ' \n  \n' +
            ('Subject: ') + document.querySelector('input[name="subject"] \n').value + ' \n  \n' +
            ('Brief Message: ') + document.querySelector('textarea[name="customer service"] \n  \n').value.replace(/\n/g, '<br/>');
        document.querySelector('textarea[name="email-message"]').value = value;
    }
    document.querySelector('.contact-style').addEventListener('keyup', aggregateInput);
});

document.addEventListener('DOMContentLoaded', function () {
    document.querySelector('.contact-form-button-submit').setAttribute('disabled', true);
    document.querySelector('.customform-message').addEventListener('keyup', function () {
        if (this.value.length != 0) {
            document.querySelector('.contact-form-button-submit').setAttribute('disabled', false);
        } else {
            document.querySelector('.contact-form-button-submit').setAttribute('disabled', true);
        }
    });
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading