1

How to get image instead of image name in html using file input type. I have used the css file for positioning the image file. I have tried all the sorts of code given... Please help.

<input type="file" name="photo" id="photo" onchange="readURL()"/>


function readURL()
{
   document.getElementById('previewimage').style.display='block';
}
1

1 Answer 1

1
function readURL()
{
if (document.getElementById('photo').files && document.getElementById('photo').files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
    document.getElementById('previewimage').src = e.target.result;
};
reader.readAsDataURL(document.getElementById('photo').files[0]);
}
}
function openFiledialog(){  
  document.getElementById('photo').click();
}

//

<input type='button' onclick='openFiledialog()' value='photo'/>
<input type="file" style='display:none;' name="photo" id="photo" onchange="readURL()"/>
Sign up to request clarification or add additional context in comments.

3 Comments

try uploading smaller images
oh.. how to make the name of the image to disappear. Is that default while using input type file?
use this update code, only buton will be visible to the user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.