This week's book giveaway is in the Features new in Java 9 forum.
We're giving away four copies of Java 9 Revealed and have Kishori Sharan on-line!
See this thread for details.
Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Nelvin Corbita
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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.....
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65893
135
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Posts: 65893
135
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Posts: 65893
135
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Posts: 65893
135
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
I tried this code but none is shown in the console and no alert
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65893
135
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
I changed my code to

I removed also the onchange in the select control but no result...
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65893
135
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Posts: 65893
135
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!