toggle2 is defined within the scope of toggle1, so it isn't a global and is not accessible.
You could assign it to a global:
function toggle1() {
//code toogle1
function toggle2() {
//code toogle2
}
window.toggle2 = toggle2;
}
… but it wouldn't be available until toggle1 was called.
Globals are generally a bad idea though. In most cases you are usually better off not using them. This makes the onXXX attributes unusable so you would have to switch to something more modern (addEventListener, either directly or through an abstraction library).
function toggle1() {
//code toogle1
function toggle2() {
//code toogle2
}
document.querySelector('form').addEventListener('submit', toggle2);
}
You'd still need to call toggle1 before it could be used though.
toggle1()?toggle2()outside oftoggle1()to make it global. Case solved.