...

View Full Version : Disable mouse entirely!



ShMiL
02-24-2003, 05:19 PM
I coded a discussion forum which it's buttons (like B,I,U) are the same as in CF posting page...
I added a function which disables the submit button once the form is being submitted in order to avoid repeated submissions.

My problem is that after submitting the form, it takes time before the user is being redirected to see his post. In that time, the user can still click the buttons (B,I,U) and if he clicks on it, the submissions get stuck (due to return false;).
I'm looking for a script which will disable any click of the mouse after submission so the user won't be able to click the buttons (B,I,U) after submission.

I hope I was clear about my prob.
Thanks for any help!

brothercake
02-24-2003, 05:55 PM
Forget that approach - disabling mouse clicks, even briefly, is an accessibility nightmare.

What you need is flood control - don't allow the same referrer to post more than once every 15 seconds or something; just get your server to reject the others.

cg9com
02-24-2003, 06:14 PM
couldnt you disable the other buttons as you did the submit?

arnyinc
02-24-2003, 06:32 PM
I'm pretty sure you can disable an entire form.

I know this works:

<form disabled>

I assume you can do something similar with javascript:

document.myformname.disabled

I tried testing that, but I don't have any way to delay it to see if the form actually gets disabled.

ShMiL
02-24-2003, 07:13 PM
Thanks for your help BUT the buttons has nothing to do with the form. It's just a JS function which adds chars to the text...
Any other idea?

arnyinc
02-24-2003, 07:38 PM
I'm still not sure if this idea is the correct solution, but you can just include these buttons in your form or create a new form for them.

Here's some very rough code...

<form name="formatting">
<input type="button" value="bold">
<input type="button" value="italic">
<input type="button" value="underline">
</form>

<form name="other_form" onsubmit="document.formatting.disabled">
all your stuff goes here
<input type="submit">
</form>

Beck
02-24-2003, 10:25 PM
"In that time, the user can still click the buttons (B,I,U) and if he clicks on it, the submissions get stuck (due to return false)"

When the user clicks these buttons, functions run certain controls that control formatting and then return false on the associated form submission, right? So you've got something like the following:

In the header:
function doItalics () {
...
return false;
}


in the body
<input type=button value=italics onclick=doItalics()>

(at least I'm guess it's something kinda like it).

Why don't you redirect the doItalics function to not return false after submission? For instance:

in the header
function doItalics () {
...
return false;
}
function submitForm () {
doItalics = dummyItalicsFunction; // syntax might wrong
document.formname.submit();
}

function dummyItalicsFunction () {
window.status = "You've already submitting your form. Please wait.";
}

in the body
<input type=button value=italics onClick=doItalics()>
<input type=button value=submit onClick=submitForm()>

This script essentially calls the submit action of the form manually through a javascript click and submit method, and in the meantime disables the italics, mainly the return false portion. This particular script might be hurting for actual syntax (eg, not sure if it's doItalics = new Function { whatever }) but I know something of this nature can be done, and then thge return false never happens.

Anyone want to comment on the correction of the above redefinition is welcome to it. I'm aiming at a concept, but didn't test it.

ShMiL
02-25-2003, 07:08 AM
Beck
I really like your suggestion.
Let me check it...

:)

ShMiL
02-25-2003, 07:11 AM
Originally posted by brothercake
Forget that approach - disabling mouse clicks, even briefly, is an accessibility nightmare.

What you need is flood control - don't allow the same referrer to post more than once every 15 seconds or something; just get your server to reject the others.
I don't want to use server-side where I can use JS - why make the server tired? ;)

ShMiL
02-25-2003, 07:17 AM
Is there a way to run a loop and change/disable all the HREFs property for all the <a> tags?

Beck
02-25-2003, 08:49 AM
Here's a link disable possibility:

in the head:
var myLinks = new Array ();
myLinks[0] = "http://www.yahoo.com/";
myLinks[1] = "http://www.google.com/";
myLinks[2] = "http://javascript.internet.com/";

in the body, each a tag looks something like:
<a href="JavaScript: window.location = myLinks[0];">Visit Yahoo!</a>

of course, you have to assign the array properly, and all that. But if you follow this pattern for every link on the page, then you can disable all the links you want to by calling the following function:

function disableAnchors () {
for (var i = 0; i < myLinks.length; i++)
myLinks[i] = "#";
}

I suppose you'd call it after submitting your form:
function submitForm () {
...
disableAnchors ();
...
}

That way, none of the links go anywhere.

Any of the Gurus see any yuckies in my script? Don't let me steer this guy wrong! :)

ShMiL
02-26-2003, 05:16 AM
I thought that there was a way of doing it without creating the array manually (like in images...).

Anyway, I had a better idea and it works: I put an empty <span id="span1"> before the post form, and wrapped the form itself with <span id="span2">
and onSubmit I:
1. span2.style.display='none';
2. span1.innerHTML = 'Please wait while posting';

It works fine for me, will it be compatible with other browser (than IE 6)?

Thanks.

ShMiL
02-26-2003, 06:00 PM
anyone know about he compatibility?

Roy Sinclair
02-26-2003, 07:03 PM
It won't work in other browsers unless you change your references:

span2.style.display='none';

should be:

document.getElementById("span2").style.display='none';

Using the IE only shortcuts to objects is the primary way to make pages that could easily be cross-browser into IE only pages.

ShMiL
02-26-2003, 07:17 PM
Didn't know that, thanks Roy!


I wish I had more time to learn...
SCHOOL SUCKS!!!

beetle
02-26-2003, 08:44 PM
Originally posted by ShMiL
I don't want to use server-side where I can use JS - why make the server tired? ;) Uh, because of a litte something like this
"Machines are meant to make life easier for us. ... the machine works hard so you don't have to. That's the way it's supposed to be. If we're working hard to make the machine's life easier, then we're doing something wrong."Maybe?

ShMiL
02-26-2003, 09:44 PM
Why do you consider coding two lines of JS as "working hard"? Why coding JS is harder than coding vbscript?
You code only once, and then it runs for years. Why not make it as efficient as possible?

Anyways, I found a good solution. Thanks for your help!

beetle
02-26-2003, 09:47 PM
I don't, I also dont' consider a few lines of PHP working hard either. Besides, I'm a fan (http://www.peterbailey.net/fValidate/) of doing things client-side first ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum