HTML -
- <input type="file" id="imageUpload3" onchange="previewimg(this)" />
- <br />
- <div id="dvPreview3" style="margin-top: 40px;">
- </div>
Jquery function -
- <script>
- function previewimg(evt) {
- var regex = /^([a-zA-Z0-9\s_\\.\-:()])+(.jpg|.jpeg|.gif|.png|.bmp)$/;
- if (regex.test($(evt).val().toLowerCase())) {
- if ($.browser.msie && parseFloat(jQuery.browser.version) <= 9.0) {
- alert("This browser does not support FileReader.");
- }
- else {
- if (typeof (FileReader) != "undefined") {
- $("#dvPreview3").show();
- $("#dvPreview3").html("<img/>");
- var reader = new FileReader();
- reader.onload = function (e) {
- $("#dvPreview3 img").attr("src", e.target.result);
- }
- reader.readAsDataURL($(evt)[0].files[0]);
- } else {
- alert("This browser does not support FileReader.");
- }
- }
- } else {
- alert("Please upload a valid image file.");
- $('#imageUpload3').val('');
- }
- }
- </script>
Once you browse images using fileupload control, you can preview images in the bottom.