0

As a part of a register form, I am just checking if name is typed or empty. Here's the HTML

<div class="text form-group justify-content-center mx-auto col-12">
     <input type="text" id="name" class=" " name="name" onkeyup='name_val();'>
    <label for="name"><span class="content">&nbsp;&nbsp;Name</span></label>
</div>
<p id="compare_name" class="text-center"> </p>

And here's the script.

var name_val = function (){
if($('#name').val() == ""){
    document.getElementById('compare_name').style.color = 'red';
    document.getElementById('compare_name').innerHTML = 'This field can\'t be empty';
}
else{
    document.getElementById('compare_name').innerHTML = '';
}}

I have referenced jQuery on top of all scripts. But i still get this error.

Uncaught ReferenceError: name_val is not defined at HTMLInputElement.onkeyup

I hope somebody could help me. Thanks in advance:)

HariS
  • 3
  • 2
  • Does this answer your question? [Uncaught ReferenceError: $ is not defined?](https://stackoverflow.com/questions/2075337/uncaught-referenceerror-is-not-defined) – Ivar Apr 25 '20 at 12:34
  • How exactly did you "referenced jQuery on top of all scripts"? – Pointy Apr 25 '20 at 12:35
  • @Pointy after the closing body tag, first script referenced was and then all other scripts – HariS Apr 25 '20 at 12:39
  • Well the problem is that either your jQuery import is not working, or that some other script is removing the global `$` binding. Without seeing more code it is impossible to provide any more help. – Pointy Apr 25 '20 at 12:40

1 Answers1

-1

Try this...

function name_val() { ...

// Content here...

... }

I hope this will work...