Faster way to run function?

I’m wondering if there’s a faster way to run generate(). My page contains

<form name="Form1">[…]<input maxlength="2" name="length" id="length" size="2" type="text" /><input name="generator" type="button" value="Generate" onclick="generate()" />[…]<input name="result" id="result" size="20" type="text" />[…]</form>

and its script is

var inputLength, inputResult;

document.addEventListener('DOMContentLoaded', (e) => {
	inputLength = document.getElementById("length");
	inputResult = document.getElementById("result");
});

function generatePass(pLength){
// code of https://stackoverflow.com/questions/1497481/javascript-password-generator#15894056 by Sumit Tawal
}

function generate(){
	inputResult.value = generatePass(inputLength.value);
}

which has a working version on https://jsfiddle.net/a8uw1o9j/ Perhaps inputLength = document.getElementById(“length”).value and generatePass(inputLength) instead?

Update 1
To clarify, in this thread I’m not concerned how fast generatePass() is run and I may very well replace that function.

There is no need for that to run any faster but it could be simplified:

When it comes to generating passwords, I feel much more comfortable about the process when a reliable library is used for the task instead, such as https://www.npmjs.com/package/generate-password

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.