p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript How-To (http://p2p.wrox.com/forumdisplay.php?f=87)
-   -   Hide button image (http://p2p.wrox.com/showthread.php?t=48307)

aware September 26th, 2006 07:54 AM

Hide button image
 
Hi All

I have a form that uses the input type = image to submit.

Some stupid users are hitting the save image several times in quick succession and causing an error.

Is there a way to disable the image button in javascript on the first click, or does anyone have a more elegant solution.

The form does not submit immediately, I do some validation first, and return true if OK, so any javascript could go there.

ANdy


joefawcett September 26th, 2006 09:02 AM

Code:

<form onsubmit="return trySubmit();"><input type="image" id="cmdSubmit">
function trySubmit()
{
 document.getElementById("cmdSubmit").disabled = true;
 var isValid = validateForm();
 if (isValid)
 {
   return true;
 }
 else
 {
   document.getElementById("cmdSubmit").disabled = false;
   return false;
 }
}

This assumes your validateForm function returns true or false and alerts the user to the problem.

--

Joe (Microsoft MVP - XML)

aware September 26th, 2006 05:34 PM

Thanks Joe, But....

I have tried something similar and it won't work, I have tried your code and get the same thing. The pages sort of stops and wont submit.

With your sample I can do an alert() and get all the right things, but the page stops at the line where we disable the image.

Here is my code, can you see anything wrong?

<input name="btnGo" id="btnGo" type="image" src="../images/SP_Save.gif" alt="Save Rating" onClick="return Validate()">


function Validate() {

    var ErrorMessage = '';

        if (document.frmRate.txtSDM.value == '') {
        ErrorMessage = ErrorMessage + 'SDM Approval\n';
        document.frmRate.txtSDM.className = 'Error';
        }

        document.getElementById("btnGo").disabled = true;

        return true;
        }
        else {
        alert(ErrorMessage);

        // Turn save btton back on if save cancelled
        document.getElementById("btnGo").disabled=false;

        return false;

        }
}



All times are GMT -4. The time now is 03:24 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.