Why does my function keep crashing the page? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why does my function keep crashing the page?

I'm new to javascript and I can't figure out why my page keeps crashing when I run this function: function q1check() { var x= document.getElementById("q1form").value; if (x=="V") {var correct = document.getElementById("q1ans").innerHTML = "&#9989";} else {var incorrect = document.getElementById("q1ans").innerHTML = "&#10060"; var inccom = document.getElementById("q1comm").innerHTML = "Check Section 2"} } It will give the desired output and then crash the page. Any help would be greatly appreciated.

24th Mar 2019, 1:53 AM
Jim Hough
2 Answers
+ 5
I can't find any errors besides this one: the variable x will not ever = "V". You should use .innerHTML instead.
27th Mar 2019, 3:58 AM
Adler Vuong
Adler Vuong - avatar
0
The problem was on the html side. Was using a form instead of a simple input. It made the input dissapear almost as soon as it was submitted
30th Mar 2019, 6:31 PM
Jim Hough