PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, July 29, 2022

[FIXED] How to show and upload images with javascript in asp.net?

 July 29, 2022     image, javascript, jquery     No comments   

Issue

I don't known how to show images and upload with Javascript, don't use ( input type file of html , control fileupload asp.net ) . I want to use as follow

#img{width:100px;height:100px;}
<div id="img"></div>
<button type="button" id="bt_image">Image</button>
<button type="button" id="bt_save">Save</button>

When I click button Image , show dialog choose file, choose file image and the image will show on div img, click button Save , this upload in server. Thank you.


Solution

Try this example - there's an upload button, and a preview area, all you need to add is the upload button.

<form id="form1" runat="server">
    <input type='file' id="imgInp" />
    <img id="blah" src="#" alt="your image" />
</form>

And the js:

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

        reader.onload = function (e) {
            $('#blah').attr('src', e.target.result);
        }

        reader.readAsDataURL(input.files[0]);
    }
}

$("#imgInp").change(function(){
    readURL(this);
});


Answered By - Dmitry Sadakov
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing