What is wrong with this code? - - <!Doctype html> <head> </head> <body> <form> <input type="text" id="input"> </form> <button type="button" id="button">Click here</button> <script> var input=document.getElementById("input"); var button=document.getElementById("button"); function display() { if (button.clicked == true) { console.log("input"); } }; display(); </script> </body> | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is wrong with this code? - - <!Doctype html> <head> </head> <body> <form> <input type="text" id="input"> </form> <button type="button" id="button">Click here</button> <script> var input=document.getElementById("input"); var button=document.getElementById("button"); function display() { if (button.clicked == true) { console.log("input"); } }; display(); </script> </body>

Need someone for debugging

24th Oct 2016, 1:26 PM
Tomaž Roblek
Tomaž Roblek - avatar
6 Answers
+ 2
Where did you get "button.clicked" from? I don't see it anywhere else in your code. Also, there's nothing in your code that registers a click when you actually click the button. You need an event handler.
25th Oct 2016, 6:15 PM
Alex
Alex - avatar
+ 2
take a look a this, it's a basic example of exactly what you are trying to do. http://www.w3schools.com/jsref/event_onclick.asp
25th Oct 2016, 10:16 PM
Alex
Alex - avatar
+ 1
you are calling display function at script when it load and you are testing conditions that does button pressed or not so it will be false conditions so it won't work
5th Nov 2016, 4:47 PM
P'ram Kadam
P'ram Kadam - avatar
0
thanx...but i still dont get it
25th Oct 2016, 7:00 PM
Tomaž Roblek
Tomaž Roblek - avatar
0
hi Thomaz, what do you want with the code? a button that if is clicked you receive a message o console with text inserted on input box, is it? so we insert a text on input box and pressing the button, the text is show on console.log. is that??
27th Oct 2016, 2:22 PM
smutans
smutans - avatar
0
guys how will I run a function in JavaScript that after clicking submit it will take me to another page if the condition is true
18th Nov 2016, 9:04 PM
oyeniyi adedayo