+ 3

why iam getting an error in thies code ?

Iam trying to pass a value to inputbox when user clicks hello but it is not working.Iam new to js so can u pls help me https://code.sololearn.com/WyDb4z2UnxqZ

14th Jun 2020, 2:59 PM
Vijay(v-star🌟)
Vijay(v-star🌟) - avatar
9 Réponses
+ 5
V-star🌟 Write js code inside this window.onload = function() { }
14th Jun 2020, 3:18 PM
A͢J
A͢J - avatar
+ 5
It works if you follow AJ Anant instructions onload = () => { const a =document.querySelector(".item"); a.addEventListener("click", () => { //.... Your code } }
14th Jun 2020, 3:31 PM
Ore
Ore - avatar
+ 3
V-star🌟 Not showing any error. Can you show what you did? Check here https://code.sololearn.com/WCPtwhL29Orw/?ref=app
14th Jun 2020, 3:32 PM
A͢J
A͢J - avatar
+ 3
Thank you all for your help 😄
14th Jun 2020, 3:45 PM
Vijay(v-star🌟)
Vijay(v-star🌟) - avatar
+ 2
Still it's showing some error
14th Jun 2020, 3:28 PM
Vijay(v-star🌟)
Vijay(v-star🌟) - avatar
+ 2
I don't know if I'm correct of this, but it also seems like you're listening for an event, but not calling anything after it. You could try creating a function, then calling ir after addEventListener... Then also wrap your code inside a 'window.onload(){}' or 'window.addEventListener("DOMContentLoaded", init(){}' where init is the name of the function you want to execute
14th Jun 2020, 3:30 PM
Thomas Sankara
Thomas Sankara - avatar
+ 2
you also have no button in your HTML
14th Jun 2020, 7:19 PM
Joshua Flynn
Joshua Flynn - avatar
+ 2
Joshua Flynn Doesn't matter because he is clicking on Hello word.
14th Jun 2020, 7:46 PM
A͢J
A͢J - avatar
+ 2
Your HTML <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <div class="item"> <label>helo</label> </div> <input type="text" id="mytext"/> </body> </html> /* if what you want is to show the content of the input box on the div when you click on the div, try this code */ const a =document.querySelector(".item"); a.addEventListener("click", () => { a.innerHTML = document.getElementById("mytext").value; });
16th Jun 2020, 9:13 AM
Bede Asonye
Bede Asonye - avatar