Add two functions to window.onload
Solution 1:
window.addEventListener("load",function(event) {
var $input2 = document.getElementById('dec');
var $input1 = document.getElementById('parenta');
$input1.addEventListener('keyup', function() {
$input2.value = $input1.value;
});
},false);
window.addEventListener("load",function(){
document.getElementById('enable').onchange=function(){
var txt = document.getElementById('gov1');
if(this.checked) txt.disabled=false;
else txt.disabled = true;
};
},false);
Documentation is here
Note that this solution may not work across browsers. I think you need to rely on a 3-rd library, like jquery $(document).ready
Solution 2:
If you can't combine the functions for some reason, but you have control over one of them you can do something like:
window.onload = function () {
// first code here...
};
var prev_handler = window.onload;
window.onload = function () {
if (prev_handler) {
prev_handler();
}
// second code here...
};
In this manner, both handlers get called.
Solution 3:
Try putting all you code into the same [and only 1] onload method !
window.onload = function(){
// All code comes here
}
Solution 4:
You cannot assign two different functions to window.onload
. The last one will always win. This explains why if you remove the last one, the first one starts to work as expected.
Looks like you should just merge the second function's code into the first one.
Solution 5:
window.addEventListener will not work in IE so use window.attachEvent
You can do something like this
function fun1(){
// do something
}
function fun2(){
// do something
}
var addFunctionOnWindowLoad = function(callback){
if(window.addEventListener){
window.addEventListener('load',callback,false);
}else{
window.attachEvent('onload',callback);
}
}
addFunctionOnWindowLoad(fun1);
addFunctionOnWindowLoad(fun2);