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

Link to Function

P: n/a
I have seen partial answers to the following question but I am not sure
of the best approach. I have a page that will only work with
javascript. The link to the page indicates that.

Within the page I have a clickable link to a function. The best html
for that process seems to be:
<a href="xxx" onclick="TheFunction(); return false">CLICK HERE</a>

I assume the "return false" causes the href to be ignored but the
function will be called. Since the page is only accessed with
javascript there is no need for a url. Is there some kind of dummy
entry that can be used in place of xxx or is that ok? It seems
unnecessary to create a page that will never be accesssed.

Is this the only way to link to a function from a link?

--
Dennis M. Marks
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Dennis M. Marks wrote:
I have seen partial answers to the following question but I am not sure
of the best approach. I have a page that will only work with
javascript. The link to the page indicates that.

Within the page I have a clickable link to a function. The best html
for that process seems to be:
<a href="xxx" onclick="TheFunction(); return false">CLICK HERE</a>

I assume the "return false" causes the href to be ignored but the
function will be called.
Correct. The `return false' cancels the `click' event, so the
element is no longer considered interactive in this way after
the script engine has finished processing the expressions.
Since the page is only accessed with javascript
How can you be sure?
there is no need for a url.
Well, there is, otherwise it is not a hyperlink and you
should use another control. Why not input[type="button"]?
Is there some kind of dummy entry that can be used in place of
xxx
You could use `#' but you will append to the history of the user
that accidentally gets there without having client-side JavaScript
support (enabled).
or is that ok?
OK would be a hyperlink to a document that explains why the feature
requires client-side scripting if it is not supported.
It seems unnecessary to create a page that will never be accesssed.
Well, that depends.
Is this the only way to link to a function from a link?


It is not, but it is the best one. Read the FAQ.
PointedEars
Jul 20 '05 #2

P: n/a
"Dennis M. Marks" <de******@dcsi.net> writes:
Within the page I have a clickable link to a function. The best html
for that process seems to be:
<a href="xxx" onclick="TheFunction(); return false">CLICK HERE</a>

I assume the "return false" causes the href to be ignored but the
function will be called. Since the page is only accessed with
javascript there is no need for a url. Is there some kind of dummy
entry that can be used in place of xxx or is that ok?
A link, as made with <a href="..."> is meant to link to another
page or resource. If you don't link to one, you shouldn't use
a link. If you just want something to push, use a button, that's
what they are made for:
<input type="button" value="CLICK HERE" onclick="TheFunction()">

If you insist on using a link, the most harmless href you can use
is
href=""
The empty string is a valid URL fragment, and it should refer
to the page itself. Older browser might get confuzed, though.
It seems unnecessary to create a page that will never be accesssed.
The don't make a link.
Is this the only way to link to a function from a link?


If you insist on using a link, it is the best way. If anybody mentions
"javascript:TheFunction()" then ignore it. The "javascript:" URL scheme
should generally be avoided in web pages, as there are always better
ways to achieve what you need.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.