Javascript in form

Hi!


What is the right/easiest way to add Javascript functions to a form?

I'm adding an upload button and want to set the TWebImageContainer image after the picture is chosen. I know there is no WebCore support for this , so I would like to do it directly in Javascript.

THtmlContainer:


<label class="btn btn-xl btn-success">
    Dodaj priponko <input type="file" hidden name="imgFile" accept="image/gif, image/jpeg, image/png, image/bmp, image/tiff, image/tif, image/jfif, image/jpe">
</label>


Javascript code I would like to add:


$(":file").change(function () {
    if (this.files && this.files[0]) {
        var reader = new FileReader();
        reader.onload = imageIsLoaded;
        reader.readAsDataURL(this.files[0]);
    }
});


function imageIsLoaded(e) {
    $('img').attr('src', e.target.result);
    $('img').fadeIn();
};