I've got two separate JavaScript files linked to one HTML document and when I run it, it seems the second JS file overrides the first. I think it has to do with the window.onload being called in each file but am not sure how to work around that.
I've tried using window.onloadend on one of the JS files and window.onload on the other but with the same results, the window.onloadend is the only file that is executed.
file1.js
function init() {
applyFunction();
prefillForm();
var applyForm = document.getElementById("applyForm");
applyForm.onsubmit = validate;
}
window.onload = init;
file2.js
function init() {
currentPage();
timer();
}
window.onload = init;
<body>tag and not the start of the head - that would let you solve the onload/DOMContentLoaded check entirely and just write your code. Also consider doing work in multiple scripts in modules :]