Click to See Complete Forum and Search --> : does javascript require "return true"?
CaptainPinko
01-22-2005, 08:08 PM
I'm updating a web page for a client who site is terribly non-compliant. While editing I noticed that they have ugliest javascript for their onmouseevents and so on. Instead of callinf a function, these events have code embed into them the spans 3 or lines in my text editor. Each of them ends in "return true".
Upon seeing this I tried to recall whether the return true is required or not. So does any recall if it is required by the ECMA standard? does the final statement need to be terminated by a semi-colon?
bwkaz
01-22-2005, 11:13 PM
I know Firefox gives warnings in its javascript console if you don't return a value from an event handler. The web developer extension also has a toolbar with an icon that shows you javascript warnings / errors, and it turns on the warning icon for the same things.
I believe the "standard" way of handling DOM events in HTML, though, does not strictly require a return value. I believe it assumes true if you skip it. However, I've never been able to find the definitive W3C spec on DOM events, except the portion of DOM level 2 that handles events (and it looks nothing like the HTML event stuff), so I don't know for sure.
(I hope for your sake that those three lines of javascript aren't doing something as simple as changing an image on mouseover. Because that would be extremely irritating, especially since you can do the exact same thing with CSS and no code to run whatsoever. As long as you put an anchor tag around the image you want to change on mouse-over, anyway -- IE 6 won't honor the CSS :hover pseudo-class on anything except <a> tags. Which sucks, I know (I'd rather use CSS2.1 plus the bits of CSS3 that Gecko supports), but you probably have to support some version of IE at least.)
CaptainPinko
01-23-2005, 01:38 AM
Originally posted by bwkaz
(I hope for your sake that those three lines of javascript aren't doing something as simple as changing an image on mouseover. Because that would be extremely irritating, especially since you can do the exact same thing with CSS and no code to run whatsoever.
Don't you just know it but that's exactly what it does. Of course that's what it does. Well there aare several image that are meant to serve as button. On roll-over the button image is swapped for a more vibrant version and the central area is swapped for a gif containing the information related to the button and all the others tags are turned off. Also, a really "cute" arrow from the button pointing to ther central area appears.
How would you change an img with a:hover ?
(I'm not really a web designer, I'm trying to get a job as a back end coder and the guy threw me this project as a test so it's time to "Fake it till you make it.")
I haven't started on reviewing the JavaScript yet, I've spent all my time converting all the table formatting into div + css
*Disclaimer: I was not hired to redesign the page but merely to rewrite it and make it standard compliant so I have no choice on layout, graphics, or the company name (a really lame misspelling that makes me shudder whenever I type it).
** Among the brilliance of the original design was to put all text in .gif to look really pretty... so if you search for text on the site you get nada unless Google reads alt tags!!!! I'd post this gem but I have a feeling that would be "unprofessional".
bwkaz
01-23-2005, 03:26 PM
Ack...
Anyway, to get a:hover to switch images, try something like this for markup:
<a class="mouseover" href="whatever" title="whatever"></a> and then this for the CSS:
a.mouseover {
width: XXX;
height: YYY;
background-image: url('/path/to/nonhover/img.gif');
}
a.mouseover:hover {
background-image: url('/path/to/hover/img.gif');
} It may be possible to use a property other than background-image, but it seems to work in IE6, so whatever. You do have to make sure that the XXX and YYY match the dimensions of the images.
You may need a "display: block;" property rule in the first selector, too, but try it without.