HTML issues | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

HTML issues

Guys help me with this. In my code, after submission and being marked, in code playground, it works well and returns mark and the red and green highlights. But when ran in a browser window, it doesn't do that on submission, but when the back arrow is clicked on the window screen will the score and highlights occur. Why is this so pls? PS. Pls test the code both on code playground and on a browser window. https://code.sololearn.com/WDZegXr3KE9x/?ref=app

7th Aug 2018, 10:24 AM
Emeruche Ikenna Cole
Emeruche Ikenna Cole - avatar
3 Answers
+ 2
You should remove the onclick event from the submit button and add onsubmit event on your form <form onsubmit="return mark()"> And return false on the last row function mark() { ... return false; }
7th Aug 2018, 12:33 PM
Toni Isotalo
Toni Isotalo - avatar
+ 1
When you press the submit button it submits the form which redirects you to the action destination which is the same page since you don’t have action attribute. So the click event will not be executed. We prevent the form submission by returning false .
7th Aug 2018, 1:18 PM
Toni Isotalo
Toni Isotalo - avatar
0
Toni Isotalo WOW. IT WORKED. Pls can you explain the difference between adding the function in the onclick event of the submit button and in the onsubmit event of the form? Also what does the return false do?
7th Aug 2018, 1:11 PM
Emeruche Ikenna Cole
Emeruche Ikenna Cole - avatar