Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing readAsDataURL() for image preview
    primarykey
    data
    text
    <p>jsFiddle URL: <a href="http://jsfiddle.net/Xotic750/AjtLx">http://jsfiddle.net/Xotic750/AjtLx</a></p> <p>Been working on this all day and I can't see the issue. It's probably due to my narrow understanding of how FileReader objects work but what I'm trying to do is use readAsDataURL() to obtain images a user has selected and preview them on the screen in a table. Everything is working minus...you guessed it...the preview...well sort of. I'm thinking I'm close because the preview will work, BUT it only displays the last image of the set. Say for example if I uploaded 6 images then the first row of 3 images would be broken, the second row the first 2 would be broken, then the final 6th image would display the preview....Any advice greatly appreciated. Also, once this works it might help others trying to do the same thing because I've searched all over for a solution to this issue and I can't seem to dig anything up....</p> <pre><code>function PreviewImages() { var inputID = document.getElementById('input_clone'); var totalImages = inputID.files.length; var imagesPerRow = 3; var numRows = totalImages / imagesPerRow; var row = ""; var cell = ""; var element1 = ""; var elementID = ""; for(var i = 0; i &lt; numRows; i++){ //create rows row = document.getElementById('image_preview_table').insertRow(i); for(var ii = 0; ii &lt; imagesPerRow; ii++){ //create cells cell = row.insertCell(ii); elementID = "img_" + ii; element1 = document.createElement("img"); element1.name = elementID; element1.id = elementID cell.appendChild(element1); oFReader = new FileReader(); oFReader.onload = function(oFREvent){ var dataURI = oFREvent.target.result; var image = document.getElementById(elementID); image.src = dataURI; }; oFReader.readAsDataURL(document.getElementById("input_clone").files[ii]); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload