• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Cannot understand why function is not detected in HTML

 
Rancher
Posts: 306
16
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 3882
542
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 3882
542
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Rancher
Posts: 306
16
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 3882
542
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Rancher
Posts: 306
16
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
reply
    Bookmark Topic Watch Topic
  • New Topic