My JavaScript function not working | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

My JavaScript function not working

Why is my onsubmit function not being called? Thank you for the help :) https://code.sololearn.com/Wt3dQCaFX8a8/?ref=app

8th Feb 2022, 11:10 AM
Rishi
Rishi - avatar
7 Answers
- 1
you can't name the function submit because submit is a built-in javascript function just change the name to something else and it will work.
8th Feb 2022, 11:25 AM
Shaurya Kushwaha
+ 2
David Dolejší I followed your answer and did the below code but still not working. But when i change the function name, it works! How?? https://code.sololearn.com/WbLiVDKEl1w7/?ref=app
9th Feb 2022, 2:35 AM
Rishi
Rishi - avatar
+ 2
David Dolejší oh wow thank you! Now i have more understanding on this topic 😃
9th Feb 2022, 6:19 AM
Rishi
Rishi - avatar
0
Oh yeah thank you. What are the odds for this happening🤔 My first ever JavaScript function testing and i named it an already used name 😲
8th Feb 2022, 2:03 PM
Rishi
Rishi - avatar
0
Shaurya Kushwaha i got another doubt, i want to make that function to not do anything after submitting. In my below code, the screen goes blank after submitting and i want to avoid that, how can I do that? https://code.sololearn.com/WXvfEh2IaKp4/?ref=app
8th Feb 2022, 2:07 PM
Rishi
Rishi - avatar
0
you can put event.preventDefault(); in the function to prevent from reloading. In the submit type button it always reloads the page so event.preventDefault(); prevents from that. function submit1(){ alert("submitted!"); event.preventDefault(); }
8th Feb 2022, 2:49 PM
Shaurya Kushwaha
0
Shaurya Kushwaha thank you :)
8th Feb 2022, 2:52 PM
Rishi
Rishi - avatar