By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,598 Members | 1,894 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,598 IT Pros & Developers. It's quick & easy.

using return false from <a>

P: n/a
Do you have to use the onClick attrib to have
return false
work?

i.e. is it possible to do
<a href="javascript:somefunct();return false;">
and have the page not reload with 'false' or the browser not complain about
illegal use?
Oct 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Lee
s_m_b said:

Do you have to use the onClick attrib to have
return false
work?

i.e. is it possible to do
<a href="javascript:somefunct();return false;">
and have the page not reload with 'false' or the browser not complain about
illegal use?


Why would you want to do that? You're using the side-effect of a
feature instead of using one that was intended to execute functions.

Use:

<a href="someUrl.html" onclick="somefunct();return false">

Where someUrl.html will only be displayed if Javascript is not
enabled.

Oct 13 '05 #2

P: n/a
s_m_b wrote:
Do you have to use the onClick attrib to have
return false work?
i.e. is it possible to do
<a href="javascript:somefunct();return false;">
and have the page not reload with 'false' or the
browser not complain about illegal use?


You can't use "return false" that way. If you really want to avoid
"onClick" (which I wouldn't), you could use a workaround like this:

<html>
<head>
<script language="javascript">
function r(str) {
if (str == 'falsevalue') return;
alert('function r continues');
}
</script>
</head>
<body>
<a href="javascript:r('falsevalue');">link1</a>
<br>
<a href="javascript:r('truevalue');">link2</a>
</body>
</html>

--
Bart

Oct 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.