AJJ AJJ - 1 year ago 109
Javascript Question

Add two functions to window.onload

I have two functions on my form except one does not work if the other is active. Here is my code:

window.onload = function(event) {
var $input2 = document.getElementById('dec');
var $input1 = document.getElementById('parenta');
$input1.addEventListener('keyup', function() {
$input2.value = $input1.value;

var txt = document.getElementById('gov1');
if(this.checked) txt.disabled=false;
else txt.disabled = true;

What I mean is that when I have both these functions in my form the second function works fine but the first will not work, if take out the second function the first one will work like normal, why is this happening? Is it because of the names?

Answer Source

Try putting all you code into the same [and only 1] onload method !

 window.onload = function(){
        // All code comes here 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download