Webmaster Forum


Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Coding Forum Problems with your code? Let's hear about it.

   

Reply
 
LinkBack Thread Tools Display Modes
Old 10-09-2008, 10:22 AM   #1 (permalink)
Junior Member
 
Join Date: 10-02-07
Posts: 17
iTrader: 0 / 0%
Latest Blog:
None

twalters84 is liked by many
Disable Form Button, Back Browser Button...

Hey there,

My client was having an issue on his website where forms were being submitted more than once if the user clicked a submit button really fast.

The solution I found is as follows:

Code:
function disableSubmit(whichButton) { if (document.getElementById) { // this is the way the standards work document.getElementById(whichButton).disabled = true; } else if (document.all) { // this is the way old msie versions work document.all[whichButton].disabled = true; } else if (document.layers) { // this is the way nn4 works document.layers[whichButton].disabled = true; } }
Here is an example of a simple form that uses this function:

Code:
<form name="myLoginForm" id="myLoginForm" method="post" action="../member-login.cfm?login=1" onsubmit="disableSubmit('myLoginBtn');"> Username: <input id="MY_USERNAME" name="MY_USERNAME" type="text" class="text-very-small" maxlength="50"/>&nbsp;&nbsp; Password: <input id="MY_PASSWORD" name="MY_PASSWORD" type="password" class="text-very-small" maxlength="50"/>&nbsp;&nbsp; <input type="submit" value="Login" title="Login" id="myLoginBtn" name="myLoginBtn" class="myButtonStyle" /> </form>
This fixes that issue for users that have javascript enabled, but it creates another issue. When the user clicks the back button on their browser, the submit button is disabled.

You can view this behavior by clicking the search button on the top menu of this page:

http://www.greenhappenshere.com/find...businesses.cfm

After you click search, click the back button on your browser and notice how the search button is already disabled.

So I need a solution to this problem or a better way of disabling form buttons so forms do not get submitted more than once.

Thanks in advance for any assistance you can provide me with.

Sincerely,
Travis Walters
twalters84 is offline  
Add Post to del.icio.us
Reply With Quote
Old 10-09-2008, 11:39 AM   #2 (permalink)
v7n Mentor
 
Costin Trifan's Avatar
 
Join Date: 04-13-07
Location: Romania
Posts: 3,083
iTrader: 0 / 0%
Costin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest orderCostin Trifan is a web professional of the highest order
first thing first:
why would you do something like that (disabling the button) for a SEARCH button?? I've never seen that before...that kind of behavior is mostly used for contact forms or forms that when submitted insert data into a database...

anyway, you can prevent that by enabling the button in the page load event:
Code:
window.onload = function() { document.getElementById('your-button-id').disabled = false; };
Costin Trifan is offline  
Add Post to del.icio.us
Reply With Quote
Old 10-09-2008, 01:33 PM   #3 (permalink)
Junior Member
 
Join Date: 10-02-07
Posts: 17
iTrader: 0 / 0%
Latest Blog:
None

twalters84 is liked by many
Hey there,

Thanks for your prompt response.

If the disable code was not there, the form would be submitted to the server multiple times. So I am doing it in that case there to keep the server load down.

I am more concerned with add forms though. If those forms get submitted more than once, the website can get spammed very easily.

Sincerely,
Travis Walters
twalters84 is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum

Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Form button half working gridsix Web Design Lobby 2 03-08-2008 09:06 PM
Multi-Function Form Submit Button brokenshadows Web Design Lobby 4 01-29-2008 05:11 AM
Need Help: Form submit and IE Back button problem !!! cuongdm Coding Forum 4 10-27-2006 11:53 AM
javascript and back button pere Coding Forum 5 08-29-2006 12:15 PM
Make a button or image enter something into a form? Leader of Men Coding Forum 2 11-13-2003 06:25 PM


Sponsor Links
Webmaster Forum Get exposure! Find Scripts Web Hosting Directory Get exposure! SEO Blog


All times are GMT -7. The time now is 05:46 AM.
© Copyright 2008 V7 Inc