walid mahmoud
Published in : 2022-02-28

jquery undefined function


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)


Eslam Zedan Date : 2022-02-28

Best answers


Best answers


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 to toggle ( show and hide ) divs according to day hours?
Publish date: 2022-02-13 | Comments: 1

Tag: Javascript

How can I switch between two background-colors using js setinterval( )
Publish date: 2022-02-22 | Comments: 1

Tag: Javascript

Simple HTML date picker is showing not showing calendar icon!
Publish date: 2022-03-01 | Comments: 2

Tag: Javascript

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

Tag: Javascript

How to get audio input and audio output as one stream?
Publish date: 2022-02-13 | Comments: 2

Tag: Javascript

Help: How do I loop simple JSON objects to iterate all keys and values itself?
Publish date: 2022-03-06 | Comments: 1

Tag: Javascript