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.


joefawcett September 26th, 2006 09:02 AM


<form onsubmit="return trySubmit();"><input type="image" id="cmdSubmit">
function trySubmit()
 document.getElementById("cmdSubmit").disabled = true;
 var isValid = validateForm();
 if (isValid)
   return true;
   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 {

        // Turn save btton back on if save cancelled

        return false;


All times are GMT -4. The time now is 06:04 PM.

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