+ 4
I cant find error,where wrong?Why I didn't get alert message?
8 odpowiedzi
+ 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
+ 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
+ 3
What errors you facing mention more about errors
+ 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);
});
});
+ 2
Thank all ,now I find solution
+ 1
After submitting,I dont get alert message.
+ 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;
});
});
- 2
Hello