Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
405 views
in Technique[技术] by (71.8m points)

javascript - Disable Submit Button after one click with validation?

I have a form that is passing data to a cc processing terminal, as well as writing PDF contracts and receipts. There is validation built into the form, and I am trying to add a function to disable the submit button after one click provided validation is passed.

I don't know a lot about post data, but I want to make sure it:

1. Still posts the data. 2. Still validates. 3. Does not allow the user to submit multiple times.

Here is my POST chunk of code:

<form method="POST" action="partner_register_ihg.php" onSubmit="javascript:return WebForm_OnSubmit();"  id="docContainer" autoeventwireup="true" enctype="multipart/form-data" novalidate class="fb-toplabel fb-100-item-column fb-large selected-object" style="width: 800px;" data-form="preview">

And here is my submit section

<input type="submit" name="subbutton" onClick='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("subbutton", "", true, "", "", false, false))' id="subbutton" class="fb-button-special" value="Submit" />

Here is a small section of my validation code

var RequiredFieldValidator30 = document.all ? document.all["RequiredFieldValidator30"] : document.getElementById("RequiredFieldValidator30");
RequiredFieldValidator30.controltovalidate = "item56_text_1";
RequiredFieldValidator30.errormessage = "Please enter the shipping zip code.";
RequiredFieldValidator30.display = "None";
RequiredFieldValidator30.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
RequiredFieldValidator30.initialvalue = "";
var RequiredFieldValidator31 = document.all ? document.all["RequiredFieldValidator31"] : document.getElementById("RequiredFieldValidator31");
RequiredFieldValidator31.controltovalidate = "item62_0_checkbox";
RequiredFieldValidator31.errormessage = "Please agree to Terms and Conditions.";
RequiredFieldValidator31.display = "None";
RequiredFieldValidator31.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
RequiredFieldValidator31.initialvalue = "";

var ValidationSummary1 = document.all ? document.all["ValidationSummary1"] : document.getElementById("ValidationSummary1");
ValidationSummary1.showmessagebox = "True";
ValidationSummary1.showsummary = "False";
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In your submit button code just add javascript code: <input type="submit" [...] id="btn1" onclick="setTimeout(disableFunction, 1);"> and in Javascript add function:

function disableFunction() {
    document.getElementById("btn1").disabled = 'true';
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...