• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Quote ID Generator Button

New Here ,
Jul 08, 2022 Jul 08, 2022

Copy link to clipboard

Copied

I am createting a pdf form that has a unique field and button. The field is called "ID" the button is called "Generate Quote #"

 

That i have managed so far is that pressing the button will generate a random number in the ID field, however, i have noticed when testing that the # is not always the same length digit wise. I would like it to always be 13 digits. Therefor I want to add a way to add extra 0's at the end of the number string so it will always be 13 digits. I dont know if i should add this to the button, or ID field propoerties under Calculate so it takes the number generated and clacualtes it to be 13 digits. ive tried a few methods but they all seem to breeak the number generation.

Here is the Action on Mouse up javascript for the button; 

 

this.getField("ID").value = (Math.floor(Math.random()* Math.pow(10,13)));

 

if (this.getField("ID").value == "") this.getField("ID").value = (Math.floor(Math.random()*Math.pow(10,13)));

 

 

TOPICS
How to , JavaScript

Views

344

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 08, 2022 Jul 08, 2022

Copy link to clipboard

Copied

Here's an alternative way of doing that:

 

var randomNumber = "";
while (randomNumber.length!=13) randomNumber = Math.random().toString().replace(/\D/, "").substr(-13);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

I get a syntax error and im not sure why

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 11, 2022 Jul 11, 2022

Copy link to clipboard

Copied

LATEST

Post your code.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines