0

bug, button not working

https://code.sololearn.com/WrZ7UYMr9yw3/#js this is a link to a code I've written. when you select from the list and hit 'submit' it has to create an 2 elements. but it doesn't do it. please help

25th Jan 2020, 6:49 AM
Youssef Hammad
Youssef Hammad - avatar
5 ответов
+ 3
Sorry, din't notice that... I just dint read his JS code
25th Jan 2020, 7:48 AM
Alfred Juma
Alfred Juma - avatar
+ 2
The attribute onclick has not been added to your button. You need to add tge attribute to fire in the function when the button is clicked. <button onclick="FuncName()">TextEg</button> Happy coding 😉 Keep coding 🙏🏾
25th Jan 2020, 7:40 AM
Alfred Juma
Alfred Juma - avatar
+ 2
Alfred Juma There's no need to use onclick in HTML, he used it in the JS and the event listener actually works fine. Actually, this if (this.inputSetup === '') in the setup function causes the problem. If you'd like to check whether this.inputSetup is undefined you should probably use if (this.inputSetup === null) or if (this.inputSetup === undefined). At least it's clear that the setup function gets stuck on that if clause, so you might comment it out, too, until you checked the functionality of the rest of the code.
25th Jan 2020, 7:46 AM
Aaron Eberhardt
Aaron Eberhardt - avatar
+ 1
Youssef Alaa ok, sorry, I might have misunderstood the purpose of the if statement. I still don't know, what it does but if you remove it, you can change line 25 to mergePlace.appendChild(newElement); and the code works.
25th Jan 2020, 9:32 AM
Aaron Eberhardt
Aaron Eberhardt - avatar
0
Aaron Eberhardt, I just tried checking for null and undefined but it didn't work.
25th Jan 2020, 8:57 AM
Youssef Hammad
Youssef Hammad - avatar