Wetrasfer link autofill

by Arko

HTML

<div>
    <!-- input event fires when the input value has changed, nice modern way to check for differences, limitations are that some browsers don't support this event (yet)) -->
    <label for="courriel">email</label>
    <input name="courriel" class="update_wlink" /><br>
    <label for="pseudo">pseudo</label>
    <input name="pseudo" class="update_wlink" /><br>
    <label for="film">titre</label>
    <input name="film" class="update_wlink" /><br>
    <a id="wetransfer_link">link</a>
    
</div>

JavaScript

$(function() {
    $('.update_wlink').bind('input', function() {
        update_link();
    });
    
    var update_link = function() {
        var to = $("input[name='courriel']").val();
        var pseudo = $("input[name='pseudo']").val();
        var titre = $("input[name='film']").val();
        var msg = encodeURIComponent('pseudo: ' + pseudo + '\ntitre: ' + titre);
        $('#wetransfer_link').attr('href', 
            'https://www.wetransfer.com/?to=' + to +
            '&msg=' + msg);
    };
});