Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable Mutliple User Clicks

Status
Not open for further replies.

scohan

Programmer
Dec 29, 2000
283
US
I'm working with an <input image ... > tag where I'm able to click the button multiple times before the next page is displayed. This has adverse effects because certain actions are repeated (e.g. creating a file on the user's PC.) The action has to occur one time only.

Is there a way that I can trap when the user clicks the button the first time and disable to button before the user can click it again. Perhaps that's impossible and I may need to set a flag and check it in subsequent code (i.e., if already_clicked_flag = yes don't execute following code) Thanks.
 
maybe this:

<input type=button name=theButton value=&quot;The Button&quot; onClick=&quot;submitMe();&quot;>

<script>
function submitMe(){
document.formName.theButton.disabled = true;
document.formName.submit();
}
</script>

Should do it --

:)
 
Actually I am having the same problem. I have to submit information using an href tag. I am unable to use a form therefore I can not call the submit() function. Is there a way to disable the href tag after it is pressed the first time? Any suggestions would be great.

Cheers
 
Well, I suppose you could put the href into a span, and then use an onClick function for the href which would wipe out the span ????

like this:

<span id=theSpan name=theSpan><a href=&quot;whatever&quot; onClick=&quot;wipeMeOut();&quot;>Here's the link</a></span>

<script>
function wipeMeOut(){
document.theSpan.value = '';
}
</script>

I'm not sure that would work, but it seems like it probably would.

let me know if it does :)
Paul Prewett
 
Paul,

I am not very familiar with the SPAN tag. When I use the code you provided I am getting an error (IE5) that document.theSpan.value is null or invalid. When debugging, if I use the alert(document.theSpan) I get undefined. If I use alert(document.theSpan.value) I get an error. Any ideas?

Brandon
 
yep -- my bad --

it's:

theSpan.innerHTML = '';

to change the content of it.

:)
 
Paul,

You are my hero today. Everything works great. I have spent about 2 hours on it so far and gotten nowhere. Thanks for the help.

Brandon
 
:)

Thanks for saying thanks. Happy I could be of help.
 
Just got back to my PC. Thanks from me too. My input is an image. I've tried disabling via

<input type=image src=&quot;...&quot; name=theImage value=&quot;The Image&quot; onClick=&quot;submitMe();&quot;>

<script>
function submitMe(){
document.formName.theImage.disabled = true;
document.formName.submit();
}
</script>

but keep getting and error that it's null or not an object.

I was able create a variable and bump it up one upon first entry into the submit funtion, and check for > 1 upon subsequent entries, which seems to work fine.

Thanks.
 
Maybe this is too simple :) but why not just do something like this:


<script language=&quot;JavaScript&quot;>
<!--
var has_been_clicked=1;
function checkClicked() {
if (has_been_clicked==1) { return true; } else { return false; }
}
// -->
</script>
<a href=&quot; onClick=&quot;return checkClicked();&quot;>

Shouldn't that solve all the problems, as well as being more compatible than &quot;disabled&quot;?
 
I think you need to bump the variable up by one, otherwise it will always be one upon entry to check clicked and will always return true. I want it to return false when it has been clicked the second time so within check_clicked you should bump up the counter ala

var count = 0;

function validateForm(form)
{
var ret = true;

count = count + 1;
if (count > 1)
ret = false;

<do other validation stuff>
}
 
true... I wrote it rather quickly. Still, it seems easier than a span and more reliable than disabling.
 
OK, here's what I meant:

<script language=&quot;JavaScript&quot;>
<!--
var has_been_clicked=0;
function checkClicked() {
has_been_clicked++;
if (has_been_clicked==0) { return true; } else { return false; }
}
// -->
</script>
<a href=&quot; onClick=&quot;return checkClicked();&quot;>click here</a>

but for some reason it didn't work when I tested it so never mind. Don't have time to debug :-(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top