Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to stop a loop from resetting?
    primarykey
    data
    text
    <p>When generate id button is pushed once, it will disable. and the numbers will display. the last 4 digits "0001" is a loop, meaning if I didn't disable the generate id button, the last 4 digits will add 1 to the end "0002" if I were to click on the button again. For now it is disabled because I only want the user to be able to generate that once..But when I push on the submit button, my codes run and the page resets (meaning the generate ID is now available to push). So when I push the generate ID button again it the loop is reset again, meaning it displays "0001" again but not "0002". What suggestions may I have to where when I push the submit button, the loop won't reset?</p> <p><img src="https://i.stack.imgur.com/qDXgT.png" alt="enter image description here"></p> <pre><code>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; } &lt;asp:Button ID="Button1" runat="server" Onclick = "Button1_Click" OnClientClick = "javascript:return SubmitForm();" Text="Submit" Width="98px" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload