Skip to content

Commit

Permalink
Update main.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadBalti authored Oct 25, 2023
1 parent 8ec060d commit ec41008
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,26 @@ document.addEventListener('DOMContentLoaded', () => {
let fileInput = document.getElementById('file');
let img = document.getElementById('img');

fileInput.addEventListener('change', function () {
if (this.files && this.files[0]) {
let file = this.files[0];
reader.onload = function (e) {
img.src = e.target.result;
};
if (fileInput.files.length > 0) {
let file = fileInput.files[0];

reader.onload = e => {
img.src = e.target.result;
};

reader.onerror = error => {
console.error('Error reading the file:', error);
};

try {
reader.readAsDataURL(file);
} catch (err) {
console.error('Error reading the file:', err);
}
});
}
} else {
console.error('No file selected.');
}
};

}

Expand Down

0 comments on commit ec41008

Please sign in to comment.