walid mahmoud

28 Feb 2022

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" class="form-control" 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

28 Feb 2022

Best Answer

best answer

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

© 2024 Copyrights reserved for web-brackets.com