473,573 Members | 3,304 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Prevent Premature clicking on a submit button while page is refreshed

Scenario: You have a page that is TOO slow to refresh.
But it allows partial flushing of html contents. I.e.
Submit button already appears but you don't
want your users to click on it prematurely
because other parts are still coming.
Here I put a javascript the will enable only
submit button only after 5 seconds after the page
is load fully.

The prevention of button being clicked twice
is also done .
<html>
<head>
</head>
<body>

<form id="testForm" >
<input id="test" type=text>
<input type=button value="1click only" onclick="dosubm it()">
</form>

<script type="text/javascript">
<!--
var submitted = false;
var timer1=setTimeo ut('EnableClick ()', 5000);

function EnableClick() {
if (typeof submitted == 'undefined') return false;
submitted = false;
}

function dosubmit(method ) {
// prevent clicking twice
if (typeof submitted == 'undefined') return false;
if ( submitted ) return false;
submitted = true;
clearTimeout(ti mer1);
document.testFo rm.submit();
}
-->
</script>
</body

Aug 14 '05 #1
2 3805
an******@hotmai l.com wrote:
Scenario: You have a page that is TOO slow to refresh.
But it allows partial flushing of html contents. I.e.
Submit button already appears but you don't
want your users to click on it prematurely
because other parts are still coming.

How about using script to prevent submission say by disabling the submit
button. Then have an onload function that enables it.

Your method makes submission of the form dependent on JavaScript, which
it should not be, and makes users wait some arbitrary time that you
think might let the page load fully. Why 5 seconds? Some users will
have to wait longer than necessary, others will likely still not have
the form fully loaded.

Here I put a javascript the will enable only
submit button only after 5 seconds after the page
is load fully.
From the script below, you attempt to wait for 5 seconds after the
script is loaded, not when the page has finished loading. Your script
does not prevent submission anyway.

The prevention of button being clicked twice
is also done .
That should be handled at the server, not the client, and your script
does not guarantee only one submit.

<html>
<head>
</head>
<body>

<form id="testForm" >
<input id="test" type=text>
<input type=button value="1click only" onclick="dosubm it()">
</form>

<script type="text/javascript">
<!--
HTML comments in script elements are completely unnecessary and possibly
harmful, don't use them.
var submitted = false;
var timer1=setTimeo ut('EnableClick ()', 5000);

function EnableClick() {
if (typeof submitted == 'undefined') return false;
'submitted' is defined as 'false', this test will always return false.
submitted = false;
}

function dosubmit(method ) {
// prevent clicking twice
if (typeof submitted == 'undefined') return false;
'submitted' is never undefined, this test will always return false.
if ( submitted ) return false;
submitted = true;
clearTimeout(ti mer1);
document.testFo rm.submit();


This method of accessing form elements fails in Firefox, you need to
either give the form a name (testForm would be good) or use:

document.forms['testForm'].submit();

[...]

--
Rob
Aug 14 '05 #2
That is exactly the opinion I wanted! Great!

Aug 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1930
by: Lloyd Dupont | last post by:
I have a web form with multiple part. I do want the user to click the submit button to post back, so I know which functionality was triggered. unfortunately, when the focus is any text box, if the user hit ENTER the form is submitted, how could prevent that ? thanks, ... Lloyd
2
3107
by: 23s | last post by:
My site's login page has a form w/ 2 textboxes and a submit button. If I'm in either of those textboxes (i.e., either one of the textboxes has focus), in any given browser, hitting "enter" on my keyboard submits the form. Server side, I handle the click event of the submit button. This is the expected behavior, and this is the behavior...
2
2228
by: ljlolel | last post by:
I'm posting this again because I did not explain myself well the first time, so the problem was not being addressed. I made the following page ( http://perla.princeton.edu/counselors/organization.php ) solely for the purpose of showing a bug. It is not production code, it is a test, made for testing, so style really doesn't matter. This...
11
4201
by: bill | last post by:
I dynamically create buttons and associate them with an event using AddHandler. I want all the button events to fire at one time, when the page is posted, instead of when each button is clicked. How I stop the buttons from posting back when they are clicked? Thanks
5
1907
by: Alex | last post by:
Hello, I hope I can explain this properly. I'm writing an application with a tabbed-based navigation, and a form which gets filled out by users will be split into 5 subtabs. What I need is instead of the user needing to hit a SUBMIT button each time the form within a tab is complete (Before clicking the next tab), I want clicking any tab...
4
10507
ganesanji
by: ganesanji | last post by:
Hi, I have written a simple php coding for getting the name , phone number and insert the values into data base. My problem is that when ever I just click the refresh button in the browser window, it will automatically previous inserted values are once again inserted into databse as a new entry. Please anybody give the perfect coding...
1
2634
by: Kirthikaiitm | last post by:
Hi, I have a image button (APPLY) On clicking apply button how to move the content from textbox to another textarea. I wrote the code in JScript. But once i click APPLY button the form is getting refreshed and the content in test area get vanished. How to retain the value on text area or how to avoid refreshing form on clicking image...
13
1548
by: frozenade | last post by:
dear all.. I try an upload script from: http://www.phpletter.com/uploaded/projects/ajaxfileupload/ajaxfileupload.zip in online demo page, it's ok, but when I downloaded it and try to localhost, input field is always refresh after submit button is pressed. how to prevent this field from being refreshed? I tried to find out the problem but...
2
3155
by: Carlos | last post by:
Hi all, I need to know how to prevent to repeat the operations that happen when the submit button is clicked, when the page is refreshed. I noticed that if I refresh my page after the submit button is clicked, the event is again activated even though I just refreshed the page, did not push the button again..
0
7733
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7641
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7957
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7705
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6338
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5527
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
2145
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1241
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.