• 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

Problem getting JavaScript code supplied by course to run

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone,

I signed up a couple of months ago to do a basic JavaScript course through distance learning. I received a .pdf file to learn from and some directories of examples and exercises to do. Frankly the examples and exercises have been pretty buggy - but so far I've been able to sort out what the problems are and get then working.

However, I've finally found an example that doesn't work, and I can't figure out what the problem is. When I try to run it in Internet Explorer nothing happens. When I try to run it in FireFox, the output text appears for an instant in the browser, below the "Reset Page" button, but then disappears again.

It isn't even a complicated piece of code, compared to some of the DOM examples I've seen on the Internet whilst I've been trying to find out what might be wrong

What follows is the full code listing, just as it was supplied to me:



If anyone can point me in the right direction regarding what the problem might be, I'd be very grateful,

Thanks,

Don.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like a crappy course...

buttons need a return false on the click event.

Eric
 
Sheriff
Posts: 67746
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
I'm afraid I have to agree with Eric. Even outside of the glaring error, if that's supposed to be an example of best-practice JavaScript, well... it doesn't pass muster by a long-shot.
 
D. McPherson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the replies, guys.

Yes, I was already having doubts about the course. A number of the examples/exercises that have been presented so far haven't worked in one browser or another. This one has really pushed me to the edge, as it didn't work in either browser

I got the course (+ a six week Perl one) free though, since I was unemployed when I registered for them.

The material gives the impression that it has been updated repeatedly by different people, none of whom have read what's gone before, and none of whom have checked the code examples. For example, operator precedance has been covered three times By comparison, other snippets of code in the examples aren't even mentioned in the explanatory text - so their significance isn't explained.

I've just ordered the O'Reilly book on Javascript from Amazon, and I'll start doing some of the online tutorials that are on the internet - I'm 100% sure that I'll get a better understanding of Javascript from that than from the course notes. I hope that the Perl course is better - I've still got to start that

Could either of you suggest a good online JavaScript course - my natural inclination is to head straight for the w3schools site - is that one that you would recommend?

Thanks again for the replies,

Don

P.S. I changed the code as you suggested Eric and it works a treat. I assume that the purpose of "return false" is to prevent the form refreshing? Mind you, I've now found that in FireFox, the Reload Page button fails to re-enable the three "answer" buttons - there's always something else
 
Bear Bibeault
Sheriff
Posts: 67746
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
In general, returning false from an event handler blocks the default action of the event. For a form submit, it'll block the submission, for a link click it will block the redirect, and so on.
reply
    Bookmark Topic Watch Topic
  • New Topic