• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Always Uncaught ReferenceError: function is not defined when adding function in select onchange

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a view:


in my js script:


and in my controller:


I am laready using the codes above in my other projects and I have no problem at all but when I use it in my current project I always get Uncaught ReferenceError: function is not defined every time I add a function in select onchange but my other scripts is working fine.....
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use the browser tools to find out what line of script is failing.

Why are you parsing the JSON yourself rather than setting dataType to "json"?

And you are aware that console.log will fail in most browsers when browser tools aren't open, right?
 
Nelvin Corbita
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I already using console log and it's pointing in the


I am using chrome and I also tested my project in my mozilla and console log returns this onchange() means empty....
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, lose the "javascript:" prefix, it's superfluous and just clogs the code.

There is no function named showDeliveryDay in the script that you posted. Does it exist?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, you are using jQuery; you should not be using onchange at all. Use jQuery to establish event handlers.
 
Nelvin Corbita
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I looked up in elements and search the showDeliveryDays script that I created but it was not there..... Please check the attached jpg
script.jpg
[Thumbnail for script.jpg]
IDE view
console.jpg
[Thumbnail for console.jpg]
element view in chrome
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the method does not exist that explains why the error occurs.
 
Nelvin Corbita
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried this code but none is shown in the console and no alert
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The establishing code looks ok; are you sure that it's getting executed?

Also, use the .val() method on the select element to get the selected value; not by trying to find the selected option.
 
Nelvin Corbita
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I changed my code to

I removed also the onchange in the select control but no result...
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You haven't answered my question.

Set a breakpoint on line 2 and make sure that it is getting executed. If so, check that your selector is not returning the empty set. These are basic debugging steps that you should be taking.
 
Nelvin Corbita
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I did that and it really returns empty and check also the pictures that I posted. The script is missing in elements view that is why it's returning undefined...
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you are adding code to the source page, but the new code is not showing up on the browser page? Is that correct? If so, perhaps it's just a caching issue? A build issue?
 
reply
    Bookmark Topic Watch Topic
  • New Topic