Lawl Lawl -4 years ago 90
Javascript Question

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]+$/;

var input = $('#t_input1').val();
var ar = $('#t_input1').data('name');
alert("Name can have only letters and numbers.\n\n Names Already Submitted: "+ ar.join(" , "));
return false;
ar[i]= input;
alert("Your name was successfully submitted\n\n Names Already Submitted: "+ ar.join(" , ") );
i = i+1;
return false;


Answer Source

You have not included jQuery in the first fiddle, and that is why $ can not be resolved or defined error is there.

Second fiddle does includes jQuery and it is working as expected.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download