11th Jul 2020, 11:13 AM
Aparty
Aparty - avatar
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
11th Jul 2020, 11:26 AM
Abhay
Abhay - avatar
0
but how correctly I do not know then I have a mistake
11th Jul 2020, 11:37 AM
Aparty
Aparty - avatar
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
11th Jul 2020, 11:49 AM
Abhay
Abhay - avatar
0
I do not understand how
11th Jul 2020, 11:50 AM
Aparty
Aparty - avatar
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 :-)
11th Jul 2020, 11:52 AM
Abhay
Abhay - avatar
11th Jul 2020, 11:53 AM
Aparty
Aparty - avatar
0
I need to put the text from the input into a variable without windows, it gives an error
11th Jul 2020, 11:56 AM
Aparty
Aparty - avatar
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
11th Jul 2020, 11:57 AM
Abhay
Abhay - avatar
0
Well, how to get the value out of there?
11th Jul 2020, 11:59 AM
Aparty
Aparty - avatar
0
var nick; window.onload=()=>{ var nik= document.getElementById("nik"); nik.oninput=()=>{ nick=nik.value; } } function inst(){ alert(nick); }
11th Jul 2020, 12:01 PM
Abhay
Abhay - avatar
0
thanks worked
11th Jul 2020, 12:05 PM
Aparty
Aparty - avatar
0
👍
11th Jul 2020, 12:07 PM
Abhay
Abhay - avatar