Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
30
rated 0 times [  32] [ 2]  / answers: 1 / hits: 87925  / 11 Years ago, wed, may 22, 2013, 12:00:00

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;
});
}

window.onload=function(){
document.getElementById('enable').onchange=function(){
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?


More From » function

 Answers
84

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



 window.onload = function(){
// All code comes here
}

[#78099] Monday, May 20, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
gonzaloulyssess

Total Points: 225
Total Questions: 114
Total Answers: 112

Location: Iraq
Member since Fri, Jun 5, 2020
4 Years ago
;