Jump to content

Preview A Url Image Link Before Uploading


friedice

Recommended Posts

i want to display the image of a url image

while dynamically loaded on a div under the input type

is there a way to do it?

form method="POST"  action="upload.php">
 <br/><br/>
  <pre>Upload File:  <input type="file" name="images" id="images"/>
  </br>Use Url:	  <input type="text" name="urlimages" id="urlimages" style="width:280px;" value=""/>

  </pre>


  <button type="submit" id="btn">Publish Files!</button>
 </form>
  <div id="response"></div>
   <ul id="image-list"> 
   <pre><p id="imgdesc" >Description:  <textarea   rows="2"  style="width:395px;"></textarea></p></pre>
 </ul>
 <div id="imageHolder"></div>

i got upload file part to work to preview but not this one

 

i think because its on the server side ...

i tried using the same way as the input-file type method i got workin

which is this function

(function () {
var input = document.getElementById("urlimages"),
 formdata = false;
function showUploadedItem (source) {
   var list = document.getElementById("image-list"),
 li   = document.createElement("li"),
 img  = document.createElement("img");
  p = document.createElement("p");
   img.src = source;
 alert(img.src);
   li.appendChild(img);
 list.appendChild(li);
 li.appendChild(p);
}  
if (window.FormData) {
   formdata = new FormData();
   document.getElementById("btn").style.display = "none";
}

 input.addEventListener("change", function (evt) {
  document.getElementById("response").innerHTML = "checking image . . ."
 document.getElementById("imgdesc").style.display = "block";

 if (formdata) {
  $.ajax({
   url: "upload.php",
   type: "POST",
   data: formdata,
   processData: false,
   contentType: false,
   success: function (res) {
 document.getElementById("response").innerHTML = res;
   }

  });
 }
}, false);
}());

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.