I am using the following code to show or hide a table depending on the checkbox is selected or not..
<body onload="document.f.firstfield.focus(),showOnLoad();">
My Javascript is:
function showOnLoad(){
if((document.getElementById('chk').checked)){
document.getElementById('div1').style.display = "block";}else{
document.getElementById('div1').style.display = "none";}
}
Its working fine till this. But, now I wanted to use another function showSomething() which does the same functionality as above but for different checkbox and different table.
when I change my code line to this:
<body onload="document.f.firstfield.focus(),showSomething(),showOnLoad();">
both functions are not working. How can I make them both work together?
Any help is appreciated!
You need to use
;to terminate the function calls. Use:In normal JavaScript (not inline HTML), you may use a newline character or
;(you can read more about that by Googling… maybe https://mislav.net/2010/05/semicolons/ will help). When you want to use inline JavaScript but need several statements, you MUST use;. A,is never used for this kind of purpose.And not that it matters… it’s just preference… but I would create a generic function that you call, say
bodyLoad, where these three statements are executed (so the HTML would become<body onload="bodyLoad();">). It’s much easier to manage when you know "everything" you want to do on load will be inside of this function. There are other things I’d do too, but I’ll leave it at that…