functions with variables inside other functions
Posted: Mon Apr 29, 2013 7:49 pm
Ive got a form where i will be using javascript to check if different elements are met. right now ive got everything working however i want to minimise the amount of scripts im using. However i also want to run a whole bunch of scripts when the page loads. so i have a <body onload="chkAll()">
in javascript im calling a bunch of the scripts
in scripts 1-3 lets say each looks for a specific event on a specific elements id but they all more or less do the same thing.
As is i have it as the first one but it would make sense to put it as the second 1 so its not id specific (this is checking if a checkbox is checked and it will activate a hidden input).
what i want to know is how do i put a function with variables like that into another function
in javascript im calling a bunch of the scripts
Code: Select all
function chkAll(){
script1();
script2();
script3();
other1();
other2();
}
As is i have it as the first one but it would make sense to put it as the second 1 so its not id specific (this is checking if a checkbox is checked and it will activate a hidden input).
Code: Select all
<input type="checkbox" id="check1" name="check1" value="1" <?php if ($x == 1){echo "checked='checked'";}?> onclick="script1()" />
<input type="hidden" id="hide1" name="check1" value="" disabled="disabled" />
Code: Select all
function current(){
if (document.getElementById('check1').checked){document.getElementById('hide1').disabled=true;}
else{document.getElementById('hide1').disabled=false;}
}
function correct(a,b){
if (document.getElementById(a).checked){document.getElementById(b).disabled=true;}
else{document.getElementById(b).disabled=false;}
}
Code: Select all
function correct(a,b){
if (document.getElementById(a).checked){document.getElementById(b).disabled=true;}
else{document.getElementById(b).disabled=false;}
}
function chkAll(a,b){
correct(a,b);
other1();
other2();
}/*doesnt work*/
function chkAll(){
correct(a,b);
other1();
other2();
}/*doesnt work*/