Please check my mistake on form validation.... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Please check my mistake on form validation....

https://code.sololearn.com/WHv6amtaJs2U/?ref=app When I enter the name and do not check the gender and submit the form, my display get white screen and no result is shown. I dont know what is problem and how to solve it..... Help me tomorrow is my test

24th Feb 2022, 10:01 AM
Logician S
Logician S - avatar
2 Answers
+ 4
With preventDefault(event) you can prevent app from showing this empty page You also need to pass event to function call <form onSubmit="valid(event)"/> https://www.w3schools.com/jsref/event_preventdefault.asp But why this heppend when you type name, and why your radio validation dont work. Your form become valid only when name is valid, because you use return in your code. Every return will happend after some case (if is true), you set return true if name match regex, even if you change this to false, your code wont work. Everything after this line wont ever run, when code reach return it exit from function or block of code. How to solve? Well you can add variable to check is general form valid, than give 1 return true at the end, if this variable is true. Return false is fine, because you dont wanna submit form. edit: but it is better practice to show users all invalid data at once, than to do one by one. So you can return false only once also.
24th Feb 2022, 10:47 AM
PanicS
PanicS - avatar
+ 3
That's how input "submit" works in most browsers – it renders the form invisible. You can use "button" type if you don't want that. What result do you expect to get displayed?
24th Feb 2022, 10:36 AM
Lisa
Lisa - avatar