Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 26th, 2006, 07:54 AM
Authorized User
 
Join Date: Jun 2003
Location: Bromsgrove, Worcestershire, United Kingdom.
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

  #2 (permalink)  
Old September 26th, 2006, 09:02 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
  #3 (permalink)  
Old September 26th, 2006, 05:34 PM
Authorized User
 
Join Date: Jun 2003
Location: Bromsgrove, Worcestershire, United Kingdom.
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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;

        }
}



Similar Threads
Thread Thread Starter Forum Replies Last Post
Show/ Hide image while saving file. arnabghosh Javascript How-To 7 June 25th, 2007 11:49 PM
disable the hide button in the pivot menu paul20091968 Excel VBA 0 June 29th, 2006 08:59 AM
Make a image button as default submit button toshi ASP.NET 1.0 and 1.1 Basics 1 June 1st, 2006 05:25 AM
hide the Start button in Win NT carl.dufresne@sita.aero Visual C++ 0 October 15th, 2003 09:35 AM





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