+ 1
underfined
knocks here undefined https://code.sololearn.com/WH5L1Vbj92EV/?ref=app
12 Antworten
0
Declare Nick globally ,for now it's scope is limited to onload function only ,also why are you passing Nick as an argument ,you can simply remove it ,and do alert Nick
0
but how correctly I do not know then I have a mistake
0
You don't need to pass Nick as an argument to onload function since it's declared globally it's accessible inside any function
your code should be like this,
var nick;
window.onload=()=>{
nick = document.getElementById("nik").value;
};
function inst(){
alert(nick);
}
you will get an empty value when you will click on button which is right
0
I do not understand how
0
You should learn about how global and local variable works inside function ,Also please clarify what exactly you don't understand so I or anyone else can help you :-)
0
I need to put the text from the input into a variable without windows, it gives an error
0
LOID GAME it is working according to what you have coded,
See in your code when the window gets loaded, inside script is executed and therefore it gets the empty value ,and after clicking on button that empty value is seen in alert box
0
Well, how to get the value out of there?
0
var nick;
window.onload=()=>{
var nik= document.getElementById("nik");
nik.oninput=()=>{
nick=nik.value;
}
}
function inst(){
alert(nick);
}
0
thanks worked
0
👍