Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

When is onclick *not* triggered?

3 views
Skip to first unread message

Tim Slattery

unread,
May 29, 2012, 11:15:02 AM5/29/12
to
We have a legacy app that uses a somewhat odd method of submitting a
page, and it's giving us fits.

There's no "<input type='submit'...> button on the page. What is there
is an image of a "Continue" arrow surrounded in an <a ... > tag. Here
it is:

<a href="" onclick="submit_page(contactForm, 'prices');return
false;"
title="Continue through the Web site" scope="request" >
<img border="0" src="/GlobalContent/images/arrowContinue.gif"
align="middle"/>
</a>

The "submit_page" script sets a couple of values and submits the form
Works just fine, nearly always.

The problem is that in a very few cases, it looks like the href tag is
activated (for lack of a better term) without triggering the onclick.
The result is that the page is submitted to a nonexistent address.

So my question is how could this happen? I've tested tabbing to the
continue arrow, then using the enter key, CTRL-enter, and several
other combinations. All seem to work. Is there any way to activate the
"a" tag without triggering the onclick?

The errors seem to be reported by people using IE8. I've run my tests
with that browser and haven't turned up anything.

--
Tim Slattery
Slatt...@bls.gov

Thomas 'PointedEars' Lahn

unread,
May 29, 2012, 11:40:08 AM5/29/12
to
Tim Slattery wrote:

> We have a legacy app that uses a somewhat odd method of submitting a
> page, and it's giving us fits.
>
> There's no "<input type='submit'...> button on the page. What is there
> is an image of a "Continue" arrow surrounded in an <a ... > tag. Here
> it is:
>
> <a href="" onclick="submit_page(contactForm, 'prices');return
> false;"
> title="Continue through the Web site" scope="request" >
> <img border="0" src="/GlobalContent/images/arrowContinue.gif"
> align="middle"/>
> </a>

And invalid markup on top of that. I have seen such nonsense before in my
job as well.

> The "submit_page" script sets a couple of values and submits the form
> Works just fine, nearly always.

See below.

> The problem is that in a very few cases, it looks like the href tag is
> activated (for lack of a better term)

The better (and correct) wording would be "the `A' element is activated".
`href' is not a tag, it is an attribute (name).

> without triggering the onclick.

Unlikely, but possible.

> The result is that the page is submitted to a nonexistent address.

Incorrect. `""' is a same-document reference. As a result, there is a race
condition if the `click' event is not canceled (which is short for "the
default action of the `click' event is not prevented", see
preventDefault()).

> So my question is how could this happen?

Client-side scripting is not supported or the submit_page() call throws an
exception. You do not handle that exception, which is why the program
aborts. If it aborts, usually the `onclick' attribute value is processed as
if it was not there.

> The errors seem to be reported by people using IE8. I've run my tests
> with that browser and haven't turned up anything.

The nature of a race condition is that it is not reproducible or hard to
reproduce. Replace the legacy approach, and fix your function, so that
there is no race condition.


PointedEars
--
Sometimes, what you learn is wrong. If those wrong ideas are close to the
root of the knowledge tree you build on a particular subject, pruning the
bad branches can sometimes cause the whole tree to collapse.
-- Mike Duffy in cljs, <news:Xns9FB6521286...@94.75.214.39>

Richard Cornford

unread,
May 29, 2012, 11:47:25 AM5/29/12
to
On May 29, 4:15 pm, Tim Slattery wrote:
> We have a legacy app that uses a somewhat odd method of
> submitting a page, and it's giving us fits.
>
> There's no "<input type='submit'...> button on the page.
> What is there is an image of a "Continue" arrow surrounded
> in an <a ... > tag. Here it is:

So an <input type="image"> could have given the save visual
presentation.

> <a href="" onclick="submit_page(contactForm, 'prices');
> return false;"
> title="Continue through the Web site" scope="request" >
> <img border="0" src="/GlobalContent/images/arrowContinue.gif"
> align="middle"/>
> </a>
>
> The "submit_page" script sets a couple of values and submits
> the form
> Works just fine, nearly always.

Having a real submit button of some form and having onsubmit
code add the values would be more reliable (and putting these
values in the form to start with would be more reliable still).

> The problem is that in a very few cases, it looks like the
> href tag is activated (for lack of a better term) without
> triggering the onclick. The result is that the page is
> submitted to a nonexistent address.

An empty HREF should be the top of the current page, which cannot be
a non-existent page if you are already viewing it.

> So my question is how could this happen? I've tested tabbing to the
> continue arrow, then using the enter key, CTRL-enter, and several
> other combinations. All seem to work. Is there any way to activate
> the "a" tag without triggering the onclick?

Right click and select "Open link", "Open in new tab" or "Open in new
window" would bypass the onclick code (as you would not have 'clicked'
in that case).

Any error thrown in the - submit_page - function would prevent
execution from getting to the - return false; - and so the default
action of the A element would not be cancelled.

There is also a possibly that a poorly coded add-on/toolbar or similar
browser extension is interfering with the onclick code.

Also, aggressive javascript code distributed with (some) adverts could
be replacing onclick handlers (or interfering with them), but you
wouldn't put an important form on a page that also imported content
from uncontrolled sources so it won't be that.

> The errors seem to be reported by people using IE8. I've run my tests
> with that browser and haven't turned up anything.

Richard.

Tom de Neef

unread,
May 29, 2012, 5:02:29 PM5/29/12
to
"Tim Slattery" <Slatt...@bls.gov> schreef in bericht
news:gep9s7pei50vqjmuo...@4ax.com...
> We have a legacy app that uses a somewhat odd method of submitting a
> page, and it's giving us fits.
>
> There's no "<input type='submit'...> button on the page. What is there
> is an image of a "Continue" arrow surrounded in an <a ... > tag. Here
> it is:
>
> <a href="" onclick="submit_page(contactForm, 'prices');return
> false;"
> title="Continue through the Web site" scope="request" >
> <img border="0" src="/GlobalContent/images/arrowContinue.gif"
> align="middle"/>
> </a>
>

Can you leave the anchor element out; replace it with a <div onclick=...>.
(Or maybe <img> itself can have the onclick.)
Then there is no href and no race opportunity. If the onclick then fails, at
least your debugging can be more focused.
Tom


0 new messages