Looking to implement a single image upload preview function in jQuery? Want to modify it to allow for multiple image uploads with separate boxes? Check out the HTML script below.
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script>
function imagepreview(input){
if(input.files && input.files[0]){
var filerd = new FileReader();
filerd.onload=function(e){
$('#imgpreview').attr('src', e.target.result);
};
filerd.readAsDataURL(input.files[0]);
}
}
</script>
<style>
body{
font-family:arial;
}
.wrap{
border:0px solid;
width:40%;
margin:10px auto;
}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
text-align:center;
padding:10px;
}
#idupload{
display:none;
}
.input-label{
background-color:#009688;
color:#fff;
padding:5px 15px;
}
</style>
</head>
<body>
<div class="wrap">
<table>
<tr>
<th><img id="imgpreview" src="" width="100" height="100"></th>
<th><img id="imgpreview" src="" width="100" height="100"></th>
<th><img id="imgpreview" src="" width="100" height="100"></th>
</tr>
<tr>
<td><label for="idupload" class="input-label"><i class="fa fa-arrow-up"></i>upload</label><input type="file" id="idupload" onchange="imagepreview(this);" /></td>
<td><label for="idupload" class="input-label"><i class="fa fa-arrow-up"></i>upload</label><input type="file" id="idupload" onchange="imagepreview(this);" /></td>
<td><label for="idupload" class="input-label"><i class="fa fa-arrow-up"></i>upload</label><input type="file" id="idupload" onchange="imagepreview(this);" /></td>
</tr>
</table>
</div>
</body>
</html>