• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Cannot understand why function is not detected in HTML

 
Master Rancher
Posts: 268
15
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

Class assignment again:

I have an html page with different test-functions. One of those is to call a javascript function from a button.
The javascript file is in an js-folder, which is in an asset folder.
I get the error:
(index):55 Uncaught ReferenceError: fillForm is not defined
   at HTMLButtonElement.onclick ((index):55)


when I am trying to fill the oneInput form.
Does anyone knows why and care to explain?

That's the main HTML:



That's the javascript located in assets/js
 
Saloon Keeper
Posts: 2796
367
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems like your JS content is not being loaded.

Have you tried enabling the browser's developer tools to see it is logging errors or reporting anything else which might provide a clue?
 
Ron McLeod
Saloon Keeper
Posts: 2796
367
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you trying really to use ES6 modules?  I don't really know much about this, but I thought it required exporting the module's functions, and then importing them into the code which calls them.

May try changing the type attribute to specify plain old javascript??
 
D.J. Quavern
Master Rancher
Posts: 268
15
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ron,
Thank you for your reply!

I did have error 304 (the page is not loading) for a while, but then resolved (itself, mostly! I am using live-server and it appears I have to save twice sometimes....). The javascript page appears to be loading now.

I tried to import in html, and export the function from the js file with :


but I have now:
exercise-5.js:33 Uncaught SyntaxError: Unexpected token export

(I also added the change you suggested:
)
Screenshot-2019-07-08-at-05.19.08.png
[Thumbnail for Screenshot-2019-07-08-at-05.19.08.png]
 
Ron McLeod
Saloon Keeper
Posts: 2796
367
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are going to specify type="text/javascript" and not use the module system, then remove the export from the fillForm method function.

I just gave your code a quick try and it did work ...

 
D.J. Quavern
Master Rancher
Posts: 268
15
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Ron.

I have still no clue why stuff work or don't, but it's really nice to get it rolling!
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!