Prevent Default not working, not sure why
I'm supposed to press enter to submit the form
my code doesnt work on this FIDDLE but it works on this one FIDDLE2. I'm not really sure why and would like to see if anyone knows why. The code is exactly the same
var i = 0;
var allowed = /^[a-zA-Z0-9]+$/;
$('#form').submit(function(e) {
var input = $('#t_input1').val();
var ar = $('#t_input1').data('name');
if (!allowed.test(input)) {
alert("Name can have only letters and numbers.\n\n Names Already Submitted: " + ar.join(" , "));
return false;
} else {
ar[i] = input;
alert("Your name was successfully submitted\n\n Names Already Submitted: " + ar.join(" , "));
i = i + 1;
return false;
}
})
Answers 1
It is showing
$
is not defined. It is means you are not includingjQuery
in your project. addjQuery
in your code. working fiddle here