neue Funktion: pruefeDuplikat für deutsche Wörter
This commit is contained in:
parent
cc902b6bc5
commit
f4b05aea31
@ -116,5 +116,36 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
16
forms/pruefeDuplikat.php
Normal file
16
forms/pruefeDuplikat.php
Normal 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);
|
||||||
31
verben.php
31
verben.php
@ -97,5 +97,36 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Loading…
Reference in New Issue
Block a user