posted on May 9, 2019
I was searching for a way to generate a random password for a form and came up with this:
$(document).ready(function randomString() { 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); } $('#q1 input').val(randomstring); });
5
0