neue Funktion: pruefeDuplikat für deutsche Wörter

This commit is contained in:
p3t3rp1Lz 2026-05-12 18:33:56 +02:00
parent cc902b6bc5
commit f4b05aea31
3 changed files with 78 additions and 0 deletions

View File

@ -116,5 +116,36 @@
</div>
</form>
</div>
<script>
document.getElementById("input_deutsch").onblur = function() {
let wortAnzahl = 0;
let wort = document.getElementById("input_deutsch").value;
if(wort != '') {
fetch("forms/pruefeDuplikat.php", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({ wort: wort})
})
.then(r => r.json())
.then(data => {
item = data;
if(item > 0) doppeltesWortGefunden(true);
else doppeltesWortGefunden(false)
});
function doppeltesWortGefunden(gefunden) {
if(gefunden) {
document.getElementById("input_deutsch").style.color = "red";
document.getElementById("input_deutsch").value = document.getElementById("input_deutsch").value + " ! WORT BEREITS VORHANDEN !";
document.getElementById("div_speichern").style.display = "none";
} else {
document.getElementById("input_deutsch").style.color = "black";
document.getElementById("div_speichern").style.display = "flex";
}
}
}
};
</script>
</body>
</html>

16
forms/pruefeDuplikat.php Normal file
View File

@ -0,0 +1,16 @@
<?php
require_once __DIR__ . '/../includes/db_connect.php';
$data = json_decode(file_get_contents("php://input"), true);
$wort = $data['wort'] ?? '';
header('Content-Type: application/json');
$stmt = $pdo->prepare("SELECT COUNT(*)
FROM deutsch
WHERE LOWER(wort) = LOWER(:wort);");
$stmt->execute(['wort' => $wort]);
$wortAnzahl = $stmt->fetchColumn();
echo json_encode($wortAnzahl);

View File

@ -97,5 +97,36 @@
</div>
</form>
</div>
<script>
document.getElementById("input_deutsch").onblur = function() {
let wortAnzahl = 0;
let wort = document.getElementById("input_deutsch").value;
if(wort != '') {
fetch("forms/pruefeDuplikat.php", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({ wort: wort})
})
.then(r => r.json())
.then(data => {
item = data;
if(item > 0) doppeltesWortGefunden(true);
else doppeltesWortGefunden(false)
});
function doppeltesWortGefunden(gefunden) {
if(gefunden) {
document.getElementById("input_deutsch").style.color = "red";
document.getElementById("input_deutsch").value = document.getElementById("input_deutsch").value + " ! WORT BEREITS VORHANDEN !";
document.getElementById("div_speichern").style.display = "none";
} else {
document.getElementById("input_deutsch").style.color = "black";
document.getElementById("div_speichern").style.display = "flex";
}
}
}
};
</script>
</body>
</html>