I am currently working on creating two webpages. One will serve as a customization page where users can upload images and input text, which will then be displayed on another page. I am wondering if it is possible to achieve this functionality using CSS and HTML, and if so, how should I proceed.
Below is the code I am using to upload and display images:
window.addEventListener('load', function() {
document.querySelector('input[type="file"]').addEventListener('change', function() {
if (this.files && this.files[0]) {
var img = document.querySelector('img');
img.src = URL.createObjectURL(this.files[0]);
img.onload = imageIsLoaded;
}
});
});
function imageIsLoaded() {
alert(this.src);
}
This is the code for displaying images in HTML:
<input type='file' />
<br><img id="myImg" src="#" alt="your image" height=200 width=100>
Similarly, I have code to display text, but currently it only shows up on the customization page. How can I connect the two pages so that when an image or text is uploaded, it also appears on the display page?
Below is the JavaScript code for displaying text:
$(document).ready(function() {
$(".preview").on('keyup', function() {
$($(this).data('copy')).html($(this).val());
});
});
The corresponding HTML code for displaying text is as follows:
<div class="field">
<label class="paddingleft" for="fullname">Full Name</label>
<div class="center">
<input type="text" class="biginputbarinline preview" id="ShipToFullname" data-copy="#name" name="ShipToFullname" required>
</div>
</div>
<br>
Your name is:
<div id="name"></div>
In addition to the above methods, you can also use a simpler approach by directly updating the text with each keystroke:
<input onkeyup="$('#name').html(this.value)" ... />
<p id='name'></p>