function slugify(str) { return str .trim() .toLowerCase() .replace(/[^a-z0-9 -]/g, '') // Remove non-alphanumeric characters .replace(/\s+/g, '-') // Replace spaces with hyphens .replace(/-+/g, '-'); // Remove consecutive hyphens } document.addEventListener("DOMContentLoaded", function () { document.querySelectorAll("[data-slugify]").forEach(input => { input.addEventListener("input", function () { const targetId = this.getAttribute("data-slugify"); const targetInput = document.getElementById(targetId); if (targetInput) { targetInput.value = slugify(this.value); } }); }); });