+ 9
Why only one button works? and the other doesn't
why does the script works only button when the window is loaded and without loaded? and How make that the 2 buttons works? code: https://code.sololearn.com/WMqwUANQw1eV/#js Solved, in part. Surged a related quesiton: https://www.sololearn.com/Discuss/403299/where-is-positioned-the-script-inside-html-tab-when-it-is-made-in-js-tab-codeplayground code 2: https://code.sololearn.com/WIUa79ydJJMp/#html
8 Answers
+ 4
write js file like that :
window.onload=function(){
btn_make.onclick=function(){
alert("made, only with window.onload\n and button f_call is not defined, why?");
};//btn_make
}; //window.onload
function f_call(){
alert("calling, only without window.onload\n and button_make is not defined, why?");
}//f_call
+ 2
Place function f_call() outside the window.onload() otherwise it will be out of the scope once it's been loaded.
+ 2
Idk if this is correct, but now it's not throwing errors:
HTML:
<button id="btn_make" onclick="btn_make()">make</button>
<button id="btn_call" onclick="f_call()">call</button>
JS:
function btn_make(){
alert("made, only with window.onload\n and button f_call is not defined, why?");
}
+ 2
What is the position of the "script" inside the html tab, in sololearn codeplayground?
because "window.onload" is unnecessary when editing it locally, or placing the script before closing </body>
reformulated question: https://www.sololearn.com/Discuss/403299/where-is-positioned-the-script-inside-html-tab-when-it-is-made-in-js-tab-codeplayground
+ 2
@Calvin now, the question is that, when I place it directly inside html, it works, example: https://code.sololearn.com/WIUa79ydJJMp/#html
so what is the script's position inside html, when it is in codeplaygorund's JS tab?
+ 1
You cant use id name directly in Javascript
btn_make.onclick
Use getElementById function
And make sure it is called by window.onload.
+ 1
@ysraelcon
Your question keeps on reappeared on recent list.
How you did that?
With all the suggestions, your issue remind unresolved?
0
because make hasnt got onclick