Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


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

316

Likes

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

Adobe Community Professional , 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;

Likes

Translate

Translate
Adobe Community Professional , Jun 14, 2021 Jun 14, 2021
Sure. Change the last line to: if (this.getField("kd_kundenkennwort").valueAsString=="")      this.getField("kd_kundenkennwort").value = randomstring;

Likes

Translate

Translate
Adobe Community Professional ,
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;

Likes

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.

Likes

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?

Likes

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
Adobe Community Professional ,
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;

Likes

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