How to combine two scripts

// ===========for checking the size of an image
$(document).on('change', '#images', function() {
    files = this.files;
    size = files[0].size;

  //max size 50kb => 50*1000
    if (size < 1000141) {
        return true;

        //break;
        // end;
    }
    alert('File size greater than 1MB cannot be uploaded');
    return false;
});

//===========used for showing the preview of image
function readURL(input) {

    if (input.files && input.files[0]) {
        var reader = new FileReader();

        reader.onload = function(e) {
            $('#blah').attr('src', e.target.result);
            $('#blah').show();
        }
        reader.readAsDataURL(input.files[0]);
    }
}
$("#images").change(function() {
    readURL(this);
});

      

The first script shows a warning and the second gives a preview if the size is greater than 1 MB.

+3


source to share


2 answers


You can dispatch mouse events

onmouseover='firstscriptFuncname'

<space> 'second script func name'

like this



onmouseover='readURL(input) readURL(input)'

Don't use a comma to separate it, just a space is enough.

0


source


DEMO

I think you can do something like this. There are other ways that can help you with this.



// ===========for checking the size of an image
$(document).on('change', '#images', function() {
    files = this.files;
    size = files[0].size;
    //max size 50kb => 50*1000
    if (size < 1000141) {
        readURL(this);
        return true;
    }
    alert('File size greater than 1MB cannot be uploaded');
    return false;
});

      

0


source







All Articles