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

Autogenerate Password (random string)

New Here ,
Jun 14, 2021 Jun 14, 2021

Copy link to clipboard

Copied

Hello,

When opening a document, I would like to automatically fill a text field with random text (password generator).
Unfortunately I don't find much about it and my approach seems completely wrong 😞

I hope someone can help me out here 🙂


Here is my code:

 

 

function start_kundenkennwort_gen() {

//var randomstring = this.getField("kd_kundenkennwort");

var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = 8;
var randomstring = '';
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}

document.randform.kd_kundenkennwort.value = randomstring;
}

 

 

TOPICS
How to , JavaScript , PDF forms

Views

834

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

correct answers 2 Correct answers

Community Expert , Jun 14, 2021 Jun 14, 2021

Use this code:

 

var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = 8;
var randomstring = '';
for (var i=0; i<string_length; i++) {
	var rnum = Math.floor(Math.random() * chars.length);
	randomstring += chars.substring(rnum,rnum+1);
}
this.getField("kd_kundenkennwort").value = randomstring;

Votes

Translate

Translate
Community Expert , Jun 14, 2021 Jun 14, 2021

Sure. Change the last line to:

 

if (this.getField("kd_kundenkennwort").valueAsString=="")

     this.getField("kd_kundenkennwort").value = randomstring;

Votes

Translate

Translate
Community Expert ,
Jun 14, 2021 Jun 14, 2021

Copy link to clipboard

Copied

Use this code:

 

var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = 8;
var randomstring = '';
for (var i=0; i<string_length; i++) {
	var rnum = Math.floor(Math.random() * chars.length);
	randomstring += chars.substring(rnum,rnum+1);
}
this.getField("kd_kundenkennwort").value = randomstring;

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 ,
Jun 14, 2021 Jun 14, 2021

Copy link to clipboard

Copied

@try67 you are my hero. It works - thank you so much.

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 ,
Jun 14, 2021 Jun 14, 2021

Copy link to clipboard

Copied

Can you adapt the script so that it only generates the password once per document?

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 ,
Jun 14, 2021 Jun 14, 2021

Copy link to clipboard

Copied

LATEST

Sure. Change the last line to:

 

if (this.getField("kd_kundenkennwort").valueAsString=="")

     this.getField("kd_kundenkennwort").value = randomstring;

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