//====== //====== // // Template- multiclk_js.IHT by S.Huang 29-JAN-02 / 8-MAR-07 // // Purpose- // // Javascript code to ensure only one request is sent when // a submit button is clicked multiple times // // Notes- // // - This javascript is automatically included in all // standard Medianet IHT pages via JAVASCRIPT.IHT // // - To use, include the standard Medianet submit button in // your form, see SUBMIT.IHT. // // - onsubmit handlers already attached to the form will be // preserved, but environmentally sensitive onsubmit handlers, // such as those that use the 'this' variable to refer to // the current form, will not work correctly since the context // will be lost. // - To pass the current form object to an onsubmit handler // don't do this: // -
// Instead, do this: // - // // - Netscape doesn't support any property like "onClick" in TAG // , so the way we implemented it won't call // jscript function on netscape browsers. But Netscape // doesn't let you click the submit button again until after the // last request is finished, so we do not have multiple click // problem for Netscape broswers // // - Netscape 3+ and IE 3+ will support javascript1.1 // - javascript1.1 added the ability to return false to cancel the // action associated with a click event. This new feature is // used here to cancel form submit by letting isSubmitted() // return false when button is multiple clicked. // // Modifications- // // 11-MAR-02 SH / TH / PH 4=14200 // - Created // // 27-APR-04 JY / JY / JY 4= // - Added type attribute to SCRIPT tag as HTML4.01 standard // required. // // 10-OCT-06 TH / SZ / VM 1035=18522 // - Add dy_submitOwncode for application specific submit // functionality. // - Provide a default version of isSubmitted for // older browsers to prevent javascript errors. // // 10-OCT-06 TH / SZ / VM 12=18643 // - Add dy_onsubmit for form onsubmit handlers, since // ENTER in Internet Explorer does not always trigger // an onClick event. // - Add dy_onclickIsSubmitted for calling isSubmitted // from an onclick event, to allow us to record if // an onclick event has already checked the submit // when the onsubmit event is called. // - Add dy_onclickSetButton to allow identification // of the pressed button in dy_onsubmit. // // 31-OCT-06 TH / BH / HD 17=18717 // - Add notes regarding using a form onsubmit handler. // - Remove older javascript version of isSubmitted, since // current version should work in all versions of // javascript. // // 13-DEC-06 TH / BH / HD 17=18741 // - For consistancy with SUBMIT.IHT code, have submit owncode // run after other code in isSubmitted(). // - Update docs describing new onsubmit behaviour, since // previous onsubmit handlers are now preserved. // // 8-MAR-07 TH / BH / TH 17= // - Add notes on clearing submitClicked to dy_submitOwncode. // // 04-Jul-07 BG / BG / BG 12=18420 // - Converted to from .iht to .js. // //====== //====== /* Purpose: Application specific submit handling. Returns: - a 'false' return will prevent the rest of isSubmitted() from being executed. Notes: - Override this function to add application specific submit functionality. - Override must appear in the source after this definition, as the last seen definition will be used. - Prior onsubmit handlers attached directly to the form tag will run after other code in isSubmitted(), including this code. */ function dy_submitOwncode() { // If you halt the submit in here, you will likely want to // reset the submitClicked state, so that the user does not get // the standard isSubmitted() warning when they fix their problem and // try to resubmit. // submitClicked = 0; return true; } /* Purpose: Define dual-submit protection onclick event for form buttons. Example: Notes: - Since IE will not necessarily trigger a button when an ENTER press is used to submit a form, an onsubmit handler for the form should also be used to catch SUBMIT attempts, for DOM1 compliant browsers. See dy_onsubmit below. */ var submitClicked=0; function isSubmitted() { var submitOk = true; submitClicked=submitClicked+1; if(submitClicked>1) { var orderInfo="Your request is currently in the process of being submitted.\n\n" +"If you have pressed \"stop\" in your browser window and wish\n" +"to attempt to resubmit your request, first press \"refresh\"\n" +"and then re-submit your request. Note that your request may\n" +"already have been processed before you pressed \"stop\"."; alert(orderInfo); submitOk = false; } if (submitOk) return dy_submitOwncode(); return false; } var dy_submitViaOnclick = undefined; function dy_onclickIsSubmitted() { // Allow form onsubmit handler to tell an onclick submit handler // was triggered. dy_submitViaOnclick=true; return isSubmitted(); } /* Purpose: Define submit handler that is added to all forms which contain a standard Medianet SUBMIT button (see SUBMIT.IHT). Notes: - For this to work correctly, all buttons on the form should have dy_onclickIsSubmitted() attached to their onclick event. - See code in SUBMIT.IHT, which attaches dy_onclickIsSubmitted to all buttons on the form containing the SUBMIT button. */ var dy_onsubmitButton; function dy_onclickSetButton(ev) { dy_onsubmitButton = undefined; ev = dy_get_event(ev); if (ev) { var targ = dy_get_event_target(ev); dy_onsubmitButton = targ; } } function dy_onsubmit(ev) { // - Only run isSubmitted() for our standard SUBMIT button. // - Only run isSubmitted() if we haven't already done so via // an onClick handler. // - We assume SUBMIT is the standard target for [ENTER], so we // also call isSubmitted() for an [ENTER] press rather than // a button press. var returnVal = true; // submit by default. if (!dy_submitViaOnclick && (dy_onsubmitButton == undefined || dy_onsubmitButton.id.toUpperCase() == "SUBMIT")) { returnVal = isSubmitted(); } dy_onsubmitButton = undefined; dy_submitViaOnclick = undefined; return returnVal; }