After clicking the generate ID button once, it will become disabled and display a set of numbers. The last 4 digits are in a loop sequence starting with "0001". If I were to re-enable the generate ID button and click it again, the last 4 digits would increment to "0002" and so on. Currently, the generate ID button is disabled after the initial click to restrict users from generating multiple IDs. However, pressing the submit button resets the page and enables the generate ID button again. This causes the loop sequence to start over at "0001" instead of continuing from the last number. How can I prevent the loop from resetting when pressing the submit button?
var count = 0;
function counter() {
if (document.getElementById("generateid").onclick) {
count++;
return count;
}
}
function padDigits(number, digits) {
return Array(Math.max(digits - String(number).length + 1, 0)).join(0) + number;
}
function generateID() {
if (document.getElementById("generateidtxt").value == "") {
var TheTextBox = document.getElementById("generateidtxt");
TheTextBox.value = TheTextBox.value + guidGenerator();
document.getElementById("generateid").disabled = true;
}
}
function guidGenerator() {
var theID = (Year() + "-" + Month() + "-" + Day() + "-" + padDigits(counter(),4));
return theID;
}
<asp:Button ID="Button1" runat="server" Onclick = "Button1_Click"
OnClientClick = "javascript:return SubmitForm();"
Text="Submit" Width="98px"
/>