• 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

Am I doing Unobtrusive JavaScript correctly?

 
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I use buttons to navigate in my application and jQuery as our JavaScript library.

And here is demo.js

So in my $(function() { // JS Code }); of the main layout template, how to call or refer to the code in demo.js?
Sorry, I'm really new to Unobtrusive JavaScript concept.

One a side note, how not to hard code the application context in JavaScript files?
Thanks for help and time.
 
Sheriff
Posts: 67747
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

John Todd wrote:
So in my $(function() { // JS Code }); of the main layout template, how to call or refer to the code in demo.js?


All script included in the page is loaded into the same scope, so just reference anything that's loaded.

One a side note, how not to hard code the application context in JavaScript files?


In the parent JSP:
 
Hussein Baghdadi
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my main.gsp template page, what should go under:


You mentioned to use the following line in the parent JSP:

How to point to this value from a separate JavaScript file (demo.js in my case)?
Sorry if my questions sound -well not smart-.
Appreciate your time.
 
Bear Bibeault
Sheriff
Posts: 67747
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

John Todd wrote:In my main.gsp template page, what should go under:



Whatever you want. The code in this block forms a jQuery ready handler and will be executed after the DOM has been built, but before the load event is triggered.

You mentioned to use the following line in the parent JSP:

How to point to this value from a separate JavaScript file (demo.js in my case)?


contextPath

You are making this much more complicated that it is.
 
What does a metric clock look like? I bet it is nothing like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic