jcr was partly right -- that change does need to be made -- but you also have to change the way that you reference the form element. You're using a very old (Netscape 4.0-era I think) way of referencing form elements in the DOM that apparently isn't supported anymore.
Add an id="results" attribute to the text box, then change the line in your display() function to this:
That looks like it works for me to - will upload now ...
Edit: Works on the server too. Thanks.
Any idea when this changed, and how I could've searched for this? Suppose someone took a JavaScript course back in pre-Netscape 4.0 - how would they come up-to-date?
As an algorithms person I find it completely baffling trying to learn, search, and investigate this stuff. It feels completely impenetrable. I have a PhD in Pure Math, and this makes me feel really thick.
I'm not honestly sure when support for it was dropped; I know it fell out of favor at least 7 or 8 years ago. I can't quickly find a reference on the web to when support for legacy DOM was dropped, either.
How you'd get up to date depends a little on how far you want to go with Javascript. If you just want to be able to do basic stuff and then get on with your work, probably your best bet is to use jQuery and start with their tutorials (http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery). jQuery does a nice job of abstracting away many of the annoying things about the DOM and the various browser quirks associated with it.
If you wanted to really delve in to Javascript, I'm not really sure what to recommend. You would be throwing out most of the Netscape 4.0 way of doing things, and you'd eventually want to learn things like closures and Javascript's occasionally-annoying "everything is a global variable by default" and so on. One of the revered volumes would probably be best I guess: http://stackoverflow.com/questions/74884/good-javascript-boo...
I hear you on your frustration with it. Getting used to using the web inspector in Chrome or Firebug in Firefox helps, but error messages can be unhelpful, and you can find yourself swimming through lots of outdated (or incorrect, or even just "that's not how most people do things") blog posts when looking for answers. It's not quite like the good ol' days where you could drop in to a debugger and see the entire environment state and step through your code and so on. The mix of html and css and javascript also makes for this horrifically broad field of knowledge, most of which isn't really derivative, so it becomes a matter of trial-and-error and memorization.
Just a quick note of caution: id attributes are supposed to be unique to the entire document, so keep an eye out for that. document.getElementById() is the simplest way to target document elements that's supported by all browsers.
thanks thaumaturgy. I took my typical "make the problem simple" approach
and replaced the function contents with:
function displayx() {
alert("Hello Nurse!");
}
By the name change you can see my first guess was the name 'display()'
might be causing the problem.
As for Colin's question about for searching for this kind of stuff, it
helps to make the problem smaller and more isolated ("bifurcation" is
the more typical/pedantic way to say it). In this case you could search
on the very first step, the [onclick], find a working example, and
see if you can get the example to run properly.
If it doesn't work, then you probably have a script blocker
or popup blocker problem... or in my typical case, I've mistyped
something important. ;)
From there, find a simple example of calling a function from onclick, and see
if you it to run properly. If it works, then compare your code to the example.
If the simple example doesn't work, then you might have a bad example, or
you mistyped something, or there might be something odd in your browser config,
or you've just found a bug in your browser, or ... --keep trying to simplify and
isolate the problem.
The trouble with javascript searching and finding examples is finding bad examples.
They're everywhere. The volume of bad JS code on the web is just staggering, but
the worst parts are ancient, outdated and broken code still hanging around, and the
existence of countless hacks to get around browser bugs/differences. The hacks can
often look like horridly bad code, but sadly, they exist for a reason and they
are seldom explained.
Add an id="results" attribute to the text box, then change the line in your display() function to this:
That works for me.