[thelist] Javascript submit()

Paul Backhouse paul.backhouse at 2cs.com
Thu Oct 11 03:44:58 CDT 2001


Jeff,
	thanks for the help on the "#" link.
As for the the submit(); - i think ive only used it twice in all the sites
ive done.

il remember the return false; when im doing onclicks.

cheers

paul

-----Original Message-----
From: thelist-admin at lists.evolt.org
[mailto:thelist-admin at lists.evolt.org]On Behalf Of .jeff
Sent: 10 October 2001 18:46
To: thelist at lists.evolt.org
Subject: RE: [thelist] Javascript submit()


paul,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Paul Backhouse
>
> what sort of problem do you get when using the "#" - i
> have never come across any problems?
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

well, using the hash is a hack as it's intended purpose is to create links
to internal anchors within the page.  to be proper, all links that use a
hash should also include a string of text.

http://www.w3.org/TR/html4/struct/links.html#h-12.2.1

to be useful, there should be an anchor on the page uniquely named with the
same string of text (case-sensitive).

the problem that's caused by using this hack is the behavior it produces.
when the user clicks on a link using this hack, the browser will scroll the
page to the top of the document (as the link does not point to any valid
internal anchor).  if the user is already at the top of the document this
doesn't present a visible problem.  however, if the user has scrolled part
way down the page this behavior will becoming annoying really fast.
fortunately, there are ways around this.

the short-term, lazy solution is to simply add a "return false" as the final
bit in the onclick event handler.  this effectively cancels the browser's
desire to execute the href.  however, that only solves the problem for
js-enabled users.  so, what to do about the non-js users?

for one, *never* use the submit() method to submit a form where there isn't
also a regular submit button for non-js users to use.  next, when using
links as receiving points for clicks from the user, use the onclick event
handler to execute the javascript.  include the "return false" statement as
the last statement in the onclick event handler to cancel the value of the
href attribute.  include a link to a document for non-js users (hopefully
with similar functionality) in the href attribute.

<a href="blah.html"
   onClick="blah(); return false"
>blah</a>

if you absolutely cannot do this final piece, then use the javascript
pseudo-protocol in your href attribute and execute a javascript comment.
this will effectively render the link impotent to non-js users causing
nothing whatsoever to happen.  in the interests of usability, you may wish
to include a short of information in a <noscript> block to alert non-js
users why the link isn't working.  although it would probably make *way*
more sense to link to a document describing the functionality attached to
the link that they aren't able to interact with.

<a href="JavaScript://"
   onClick="blah(); return false"
>blah</a>

using javascript isn't the difficult.  using javascript responsibly is only
slightly more work.  it simply requires a little forethought prior to
implementation.

here's an article explaining the "return false" statement and canceling
events.

JavaScript: The Point of No Return ?!
http://evolt.org/article/thelist/17/8869/

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> its cool - i value any help
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

cool, good to hear.

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> - im self taught [...]
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

same here

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> and only been in this game for 2 years,
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

been here going on 4 myself.

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> i only code for PC IE and NS and Mac IE and NS [...]
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

what about with or without js support?

good luck,

.jeff

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/



---------------------------------------
For unsubscribe and other options, including
the Tip Harvester and archive of TheList go to:
http://lists.evolt.org Workers of the Web, evolt !





More information about the thelist mailing list