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 SkipVought 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 1

Status
Not open for further replies.

scohan

Programmer
Dec 29, 2000
283
0
0
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.
 
Scohan,

Had a similar problem myself and this is how I got around it, it seems to work for me but I remember that I lashed it up pretty quickly so it's probably got it's faults:

Javascript variable initialisation and function in HTML head section:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<SCRIPT language = &quot;JavaScript&quot;>

var isNS = false;
var isIE = false;

if (navigator.appName == &quot;Netscape&quot;)
{
isNS = true;
}
else
{
isIE = true;
}

var pressNumber = 0;


function buttonPressed()
{
/*
This function is here to stop multiple clicks of the &quot;submit&quot; button leading to
multiple server requests.
*/

var x;

if(isNS)
{
x = document.links['confirmLink'];
}
else
{
x = document.all['confirmLink'];
}

if (pressNumber >= 1)
{
x.href='#';
pressNumber = pressNumber + 1;
}

else
{
pressNumber = pressNumber + 1;
}
}

</SCRIPT>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

and my active link in the body needs to have a definite ID and an onClick call to the above function..

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

<a href=&quot;/servlet/bidsubmit/sb&quot; ID=&quot;confirmLink&quot; onClick=&quot;buttonPressed();&quot;><img src=&quot;/bbimages/common/images/bt_bs_yes.gif&quot; width=&quot;149&quot; height=&quot;22&quot; alt=&quot;Yes&quot; border=&quot;0&quot;></a>

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Hope that helps,

AndyB..
 
[tt]

<SCRIPT>
function ValidateForm(f) {
// f is the form object

// works in IE
f.elements['submit_image'].disabled = true;

// submit form
return true;
}
</SCRIPT>

<FORM ACTION=&quot;process.jsp&quot; onSubmit=&quot;return ValidateForm(this);&quot;>

<INPUT TYPE=&quot;image&quot; NAME=&quot;submit_image&quot; SRC=&quot;submit.gif&quot;>

</FORM>
[/tt] I hope this helped! ;-)
- Casey Winans
 
Thanks. Both methods look useful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top