Lucián Blažek Lucián Blažek - 2 months ago 8
HTML Question

Uncaught ReferenceError: $ is not defined (JavaScript/HTML in PHP)

This script I have on my site is causing some unexpected error:

Uncaught ReferenceError: $ is not defined

it should rewrite function of enter to act as a tab within the inputs on site form instead of submitting that form.

<script type="text/javascript">
$('input').keypress(function(e) {
if (e.which == 13) {
<--! says error is here within the $ symbol -->
$(this).next('input').focus();
e.preventDefault();
}
});
</script>

Answer

Thats probably because jQuery isn't defined. (I'm assuming you are using juery).

Try including jQuery first:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript">
 $('input').keypress(function(e) {
  if (e.which == 13) {
    <--! says error is here within the $ symbol -->
    $(this).next('input').focus();
    e.preventDefault();
  }
 });
</script>
Comments