+ 4

I cant find error,where wrong?Why I didn't get alert message?

https://code.sololearn.com/W6Eo3gc6Ctie/?ref=app

12th Oct 2020, 5:41 AM
DBSR🌹🌹
DBSR🌹🌹 - avatar
8 Réponses
+ 4
It is because on default, when u click on submit it will take u to another page. To stop this u have to use preventDefault function in jQuery
12th Oct 2020, 5:52 AM
Steve Sajeev
Steve Sajeev - avatar
+ 4
//Try this to solve the issue //correct id should be used, you should alert on submit i.e. form //write in correct format $(function(){ $("form").on("submit", function(){ var n = $("#nam").val(); var p = $("#pwd").val(); alert(n +" "+ p); }); }); // HAPPY CODING
14th Oct 2020, 4:44 AM
Gone
+ 3
What errors you facing mention more about errors
12th Oct 2020, 5:44 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
Use click event instead of onsubmit,you will get alert message. $(function(){ $("#sub").click(function(){ var n=$("#nam").val(); var p=$("#pwd").val(); alert("Name:"+n+" password: "+p); }); });
12th Oct 2020, 6:38 AM
Sandeep
Sandeep - avatar
+ 2
Thank all ,now I find solution
14th Oct 2020, 6:21 AM
DBSR🌹🌹
DBSR🌹🌹 - avatar
+ 1
After submitting,I dont get alert message.
12th Oct 2020, 5:48 AM
DBSR🌹🌹
DBSR🌹🌹 - avatar
+ 1
* HTML section Give your form an ID, for example "form1" as follows <form id="form1"> * JS section $(function() { $("#form1").on("submit",function() { var n=$("#nam").val(); // use # to refer by ID var p=$("#pwd").val(); alert("Name: " + n + "\nPassword: " + p); event.preventDefault(); return false; }); });
12th Oct 2020, 6:04 AM
Ipang
- 2
Hello
13th Oct 2020, 2:31 PM
Pendo Boston
Pendo Boston - avatar