aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Am I doing Unobtrusive JavaScript correctly? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Am I doing Unobtrusive JavaScript correctly?" Watch "Am I doing Unobtrusive JavaScript correctly?" New topic
Author

Am I doing Unobtrusive JavaScript correctly?

Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

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.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61662
    
  67

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:

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61662
    
  67

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.
 
 
subject: Am I doing Unobtrusive JavaScript correctly?