473,700 Members | 2,539 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 3815
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
1938
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
3113
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 irrespective of what browser I use on the login page. However... I have different page that is an...
2
2235
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 page illustrates that, for some reason, clicking on the submit button has a different effect on the...
11
4234
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
1934
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 to submit the data. I'm affraid that by not doing this, people will fill out the data in tab 1,...
4
10512
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 which will avoid automatic insertion of previous values into database..... I attched my coding...
1
2654
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 APPLY button.My button is <input type="image" src=/images/...> Pls. help regards, Kirthika
13
1554
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 I still cant. Thank you very much.
2
3164
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
8731
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8931
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7819
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6564
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5904
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4408
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4660
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2032
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.