To modify the existing code to generate 20 outputs in the specified format, you will need to adjust the JavaScript part of the code to loop and generate those outputs. I'll show you how to do this below:
- Update the HTML to accommodate the 20 outputs.
- Modify the JavaScript function to loop 20 times and generate the results.
Here is the updated code:
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Perso-Nummer Generator</title>
<style>
.output {
font-family: monospace;
margin-bottom: 5px;
}
</style>
</head>
<body>
<h1>Perso-Nummer Generator</h1>
Geburtsdatum:<br>
<input id="dob"> (Format: YYMMDD, also 01.02.1989 = 890201)<br>
Perso gültig bis:<br>
<input id="bbf"> (Format: YYMMDD, also 01.02.2025 = 250201)<br>
<a href="#" id="fill">Personalausweisnummer erstellen</a><br>
<div id="results">
<!-- Results will be inserted here -->
</div>
<hr>
Empfohlener Lesestoff: <a href="https://www.damm-legal.de/bgh-die-abfrage-von-einer-ausweisnummer-oder-postleitzahl-oder-eine-kontoueberweisung-entspricht-keinem-ausreichenden-jugendschutz-bei-einem-altersverifikationssystem">BGH Urteil
vom 18.10.2007, Az. I ZR 102/05</a><br>
Auszug: Der BGH hat […] entschieden, dass es den jugendschutzrechtlichen Anforderungen auch dann nicht genügt, wenn der Zugriff
Jugendlicher […] erst nach Eingabe einer Personal- oder Reisepassnummer möglich ist.
<script>
function ord(str) { return str.charCodeAt(0); }
function chr2int(chr) {
if (ord(chr) < 60) {
return parseInt(chr);
} else {
return (ord(chr) - 55);
}
}
function randint(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function randintleadingzero(a, b) {
var result = randint(a, b);
if (result < 10) {
result = "0" + result.toString();
}
return result.toString();
}
function genchecksum(unchecked) {
var numvalues = [];
unchecked.split("").forEach(function (singular) {
numvalues.push(chr2int(singular));
});
var sum = 0;
for (var i = 0; i < numvalues.length; i++) {
if ((i + 3) % 3 === 0) {
sum += (numvalues[i] * 7 % 10);
} else if ((i + 2) % 3 === 0) {
sum += (numvalues[i] * 3 % 10);
} else if ((i + 1) % 3 === 0) {
sum += (numvalues[i] % 10);
}
}
return (sum % 10).toString();
}
function genpersonr(dob = 0, bbf = 0) {
if (dob === 0) {
dob = randintleadingzero(30, 99) + randintleadingzero(1, 12) + randintleadingzero(1, 28)
}
if (bbf === 0) {
bbf = randintleadingzero(22, 27) + randintleadingzero(1, 12) + randintleadingzero(1, 28)
}
var aut = "";
var chars = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (j = 0; j < 9; j++) {
aut += chars[randint(0, 35)];
}
checked = aut + genchecksum(aut) + dob + genchecksum(dob) + bbf + genchecksum(bbf);
finalchecksum = genchecksum(checked);
return [
aut + genchecksum(aut),
dob + genchecksum(dob),
bbf + genchecksum(bbf) + "D",
finalchecksum,
checked + "D" + finalchecksum
];
}
document.getElementById("fill").onclick = function () {
let results = '';
let dob = document.getElementById('dob').value;
let bbf = document.getElementById('bbf').value;
if (dob === "") { dob = 0; }
if (bbf === "") { bbf = 0; }
for (let i = 0; i < 20; i++) {
let personr = genpersonr(dob, bbf);
results += `<div class="output">IDD<<${personr[0]}<<<<<<<<<<<< ${personr[1]}<${personr[2]}<<<<<<<<<<${personr[3]}</div>`;
}
document.getElementById('results').innerHTML = results;
}
</script>
</body>
</html>
In this version of the code:
- A new div with an id of
results is created to hold the 20 ID outputs.
- Inside the
document.getElementById("fill").onclick function, a loop runs 20 times, generating the IDs and appending them to the results string.
- The results string, containing 20 formatted outputs, is then inserted into the
results div.
This will ensure that when the button/link is clicked, 20 different ID strings will be generated and displayed one under the other in the desired format.