Forum Moderators: open

Message Too Old, No Replies

How to intercept a double-post whitout using onClick?

IE has a bug (?) about stopping the post when clicked again...

         

mmerlone

9:00 pm on Aug 24, 2004 (gmt 0)

10+ Year Member



I have a form with an image button to submit. If I use onClick event, everything works fine, but the mouse cursor does not change to indicate there is a link on the image. So, my boss told me to use:

<a href="javascript:if (somefunc()) document.f.submit();"><img src="bla"></a> 

function somefunc() {
var clicked = false;
if (clicked) {
alert("Please wait.");
} else {
clicked = true;
return true;
}
return false;
}

to get the cursor change.

It works nice on Mozilla, but on IE, when I make a second click, the browser stops processing and clicked remains true. Is there a way to workaround this?

Thanks for any help, and please, be nice with me, I am a beginner. :)

--
Marcio Merlone

Bernard Marx

9:05 pm on Aug 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think your boss might be "spending more time with the family" quite soon.
Er..
[pre]
var clicked = false;
if (clicked) {...
[/pre]

Bernard Marx

9:26 pm on Aug 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just an idea...

<a onclick="unclick(this);document.f.submit();return false;" href="#"><img src="bla"></a>

function unclick(elm){ elm.onclick = function(){/* do nothing */}}

[*< added*]
or without needing a function (maybe unclick is clearer though)

<a onclick="if(!this.clicked){this.clicked=1;document.f.submit()};return false;" href="#">
<img src="bla"></a>

[*added >*]

There are a lot of people who would give you a lot of reasons why it's unwise / unethical to have forms that
1. cannot be submit without javascript enabled
2. have submit buttons unnassociated with the form

You could try the

<input type="image">

submit button, or simply give the submit button styled dimensions and image background.

[edited by: Bernard_Marx at 10:06 pm (utc) on Aug. 24, 2004]

moltar

9:37 pm on Aug 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or you can even use:

<button type="submit"><img alt="" width="" height="" src="" /></button>

mmerlone

1:04 pm on Aug 25, 2004 (gmt 0)

10+ Year Member



Hello!

The

<input type="image" onclick="bla();">
worked as expected. If I use href="#" the page gets scrolled up before submit, and is undesirable.
The <button>bla</button> probably would also work, but an image input is enough for me.

I understand it is unwise to have a form that cannot be submitted without js, but you also said it is unethical. Why unethical?

Bernard Marx

2:26 pm on Aug 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The upward scrolling should be stopped by ;return false;

onclick="bla();return false;"

Unethical? Maybe it's the wrong word (depending on your politics).
People with accessibility issues will be looking for a 'proper' submit button. They should also expect to easily submit the form by pressing 'enter'.
(When I say looking, I mean 'looking' - they may well be blind)

Your call though, natch :)