# JavaScript return false



## Nummi_G4 (Jun 5, 2005)

Hey guys, I need some JavaScript help.

In this JavaScript application I was stopping the browser from following the href like so (the "return false;" is what stops the link):

```
<a href="http://www.apple.com" id="appleLink" onclick="someFunction(); return false;">Random Test</a>
```

Since putting JavaScript inline with HTML markup is a giant NO NO, I am using a JavaScript eventListener instead. Like so:

```
var appleLink = document.getElementById('appleLink');
	appleLink.addEventListener('click', appleMenuItemClicked, false);

function appleMenuItemClicked() {
  // lots of javaScript here
  return false;
}
```

However, the "return false" is no longer working while in the eventListener. Anyone know what is wrong?

For now I am just replacing the href with '#', like below, but there _must_ be a better solution.


```
function appleMenuItemClicked() {
  // lots of javaScript here
  this.href='#';
}
```


----------



## gooseman (Jun 6, 2005)

Hi,

Why is "putting JavaScript inline with HTML mark-up is a giant NO NO"? If it works across all browsers I can't see the problem.

As a Dreamweaver user, I use some of their built-in objects such as roll-over buttons, these always use inline Javascript and work on most (all?) browsers.

By using event listeners, aren't you restricting compatibility to DOM Level 2 compatible browsers only?

Sorry about the questions, but I tihnk the answer is to use inline Javascript.

Paul Perrins
www.netsourcesolutions.co.uk


----------



## Nummi_G4 (Jun 6, 2005)

gooseman said:
			
		

> Why is "putting JavaScript inline with HTML mark-up is a giant NO NO"? If it works across all browsers I can't see the problem.




To be honest, I'm not looking to support older browsers like Netscape4. Since it can't read my CSS (which is ALSO NOT in the HTML), I will just let my site break down gracefully (this will happen since I planned ahead and assembled it with that in mind).

The HTML markup should not be full of junk. 1. Markup, 2. Style, 3. Behaviour. They each get their own layer/document.


----------



## chornbe (Jun 6, 2005)

In theory.

In practice, it's nearly impossible to be such a purist. Thus is the nature of the "least common denominator" model the web has become.


----------



## ony_gosshamer (Jun 13, 2005)

I too have a javascript return false; problem:

go see:  www.lapetitefanfare.com
(For now, pretend the page is very long by making your browser window vertically small.)

Because the page is going to grow rapidly (lot's of more info is coming), I would like to be able to open and close the links without the browser window scrolling to the top at each time, nor scrolling anywhere for that matter (so no href="#").  Just simply staying there.  (like this: www.bouroullec.com)

the "return false;" doesn't seem to do it, I don't know why.

?? Any thoughts ??


----------

