user image

walid mahmoud
Published in : 2022-02-28

jquery undefined function

Javascript

Hi all 

I try to call a javascript function from a separate file, it gives me an undefined function:

I used this code in the blade file and included the js file at the bottom of the blade file 

select name="service_id" id="service_id" onChange="displaycategories(this.value)">
<script src="{{ asset('js/services.js') }}"></script>

in the service.js file I have the displaycategories function

$(document).ready(function() {
   
    function displaycategories(name) {
      // CODE
    }

});

it gives me this error

Uncaught ReferenceError: displaycategories is not defined at HTMLSelectElement.onchange (760232:303:74)

Comments

Eslam Zedan Date : 2022-02-28

Best answers

8

Best answers

8

You need to move the function outside $(document).ready(function(){…}) and before select Tag element 

Leave a comment

Join us

Join our community and get the chance to solve your code issues & share your opinion with us

Sign up Now

Related posts

How do I check if an array includes a value in JavaScript?
Publish date: 2022-02-13 | Comments: 2

Tag: Javascript

How to toggle ( show and hide ) divs according to day hours?
Publish date: 2022-02-13 | Comments: 1

Tag: Javascript

Javascript Add (+) issue
Publish date: 2022-02-26 | Comments: 1

Tag: Javascript

Can I read a local json, image or text file from Javascript?
Publish date: 2022-03-03 | Comments: 1

Tag: Javascript

Check if div have touch another div
Publish date: 2022-03-02 | Comments: 1

Tag: Javascript

Method refactoring to avoid to many npe checks
Publish date: 2022-03-05 | Comments: 0

Tag: Javascript

How to open URL in new tab & focus on it in Javascript?
Publish date: 2021-12-22 | Comments: 1

Tag: Javascript

Required to convert Obj {} to Arr [] from key-value pairs using javascript
Publish date: 2022-03-06 | Comments: 2

Tag: Javascript