Monday, June 8, 2009

Note to self...

I just wasted a few minutes on the obvious...Working on a JavaScript with Dojo, going through the excellent Mastering Dojo book from the Pragmatic Programmers.

I'm working on the script, and looking at this bit of code:

dojo.addOnLoad(function() {
dojo.connect(dojo.byId("qform"), "submit", function(e){
//stop default processing and propagation
//(we really don't want to submit the form)
dojo.stopEvent(e);

//erase any previous borders...
dojo.query("*", "fixture").style("border", "");

//set all elements found by the query to have a red border...
var query= dojo.byId("query").value;
dojo.query(query, "fixture").style("border", "2px solid red");
});
});

The error I'm getting is in the 'addOnLoad' method, with a "dojo not defined" error. Looking further up, I indeed have my dojo root specified.

See the problem? Of course not, because there is not a problem with this code. I was looking at the code (mismatched parens? missing semi-colon) when the issue was that I had retrieved the page by putting the file name in the browser, instead of the the http URL, so my code was not being served by my Apache server, therefore making it impossible to find the dojo code. Switch to an http url, and it works like a charm.

Someone is going to make the same mistake, and it's an object lesson (no pun intended) that sometimes there IS a simple solution, but that solution is often overlooked. I hope to save you a few minutes scratching your head.

No comments: