I have one input here that can upload a file into a div as it's background image. But how would I add a second input [type=file] that could upload a second image into a second div?
The second file that I want to upload is called:
<input type='file' id='getval' name="logo" />
And I want to place that file as the background-image of the div called:
<div id="logo"></div>
here's the whole thing:
document.getElementById('getval').addEventListener('change', readURL, true);
function readURL(){
var file = document.getElementById("getval").files[0];
var reader = new FileReader();
reader.onloadend = function(){
document.getElementById('adXL').style.backgroundImage = "url(" + reader.result + ")";
}
if(file){
reader.readAsDataURL(file);
}else{
}
}
h2 {
font-size: 14px;
margin: 14px 0 3px;
}
#adXL{
background-image:url('');
background-size:cover;
background-position: center;
min-height: 200px;
width: 100%;
min-width: 0;
border: 0px solid #ddd;
display: flex;
flex-direction: column;
margin: 20px 0 0 0;
background-color: #eee;
}
#logo{
background-image:url('');
background-size:cover;
background-position: center;
min-width: 0;
width: 150px;
min-height: 50px;
display: flex;
flex-direction: column;
margin: 20px;
background-color: #ccc;
}
<h2>Background Image</h2>
<input type='file' id='getval' name="background-image" />
<h2>logo</h2>
<input type='file' id='getval' name="background-image" />
<div id='adXL'>
<div id='logo'>
</div>
</div>
var file = this.files[0];