Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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

Reply With Quote
  #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)
Reply With Quote
  #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;

        }
}

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



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


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