input image html code example

Example 1: accept only image files upload html

<input type="file" name="myImage" accept="image/x-png,image/gif,image/jpeg" />

Example 2: input img

<input type="image" src="..." alt="...">

Example 3: using input file as html image source

$('document').ready(function () {
    $("#imgload").change(function () {
        if (this.files && this.files[0]) {
            var reader = new FileReader();
            reader.onload = function (e) {
                $('#imgshow').attr('src', e.target.result);
            }
            reader.readAsDataURL(this.files[0]);
        }
    });
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="file" id="imgload" >
<img src="#" id="imgshow" align="left">

Tags:

Misc Example