+ 1

Error at else whats wrong in my code?

<!DOCTYPE html> <html> <head> <title>Page Title</title> <script type="text/javascript"> function fn1() { var str1=document.getElementById("text1").value; var regx=/15K/; if(regx.test("str1")); { alert(" valid"); } else { alert(" not valid"); } } </script> </head> <body> <form> <input type="text" id="text1" placeholder=" username"><br /> <input type="password" id="text2" placeholder=" password"><br /> <button onsubmit="fn1()" type="submit">submit</button> </form> </body> </html>

25th Jan 2020, 10:16 AM
SHIVANI
SHIVANI - avatar
10 odpowiedzi
+ 3
Hi! Can you insert your code to Codes Playground (section "Codes { })? Becouse its difficult to understand in the fly (in mind)
25th Jan 2020, 10:20 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 3
Then delete ; after ) in line 13
25th Jan 2020, 11:45 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
I have tried all those every time it is showing error at "else " https://code.sololearn.com/WV5U8k5cSJhy/?ref=app
25th Jan 2020, 11:14 AM
SHIVANI
SHIVANI - avatar
+ 1
You miss { } after if (in line 13) and after else { } (line 17)
25th Jan 2020, 11:36 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
Even though it is showing error
25th Jan 2020, 11:44 AM
SHIVANI
SHIVANI - avatar
0
I'm not getting output no alert msg. I want the output as in username if text having 15K it should show alert msg else not valid alert box ...! What's the mistake
25th Jan 2020, 11:50 AM
SHIVANI
SHIVANI - avatar
0
doesn't it need some sort of eventlistener or event loop? like i think it catches the condition but just flashes it for a split second and then it goes away because it moves on to the next bit also what keeps it from continuing if the format is wrong?
26th Jan 2020, 9:14 PM
Kristina Hayes