let currentStep = 0; const formSteps = document.querySelectorAll(".form-step"); const progressSteps = document.querySelectorAll(".progress-step"); const prevButton = document.getElementById("prevButton"); const nextButton = document.getElementById("nextButton"); const submitButton = document.getElementById("submitButton"); function updateForm() { formSteps.forEach((step, index) => { step.classList.toggle("active", index === currentStep); }); progressSteps.forEach((step, index) => { step.classList.toggle("active", index <= currentStep); }); prevButton.style.display = currentStep > 0 ? "inline-block" : "none"; nextButton.style.display = currentStep < formSteps.length - 1 ? "inline-block" : "none"; submitButton.style.display = currentStep === formSteps.length - 1 ? "inline-block" : "none"; } function validateStep() { const currentField = formSteps[currentStep].querySelector("input[type='radio']:checked"); if (!currentField) { alert("لطفاً یکی از گزینه‌ها را انتخاب کنید."); return false; } return true; } nextButton.addEventListener("click", () => { if (currentStep < formSteps.length - 1) { if (validateStep()) { // فقط در صورت صحت به مرحله بعد می‌رود currentStep++; updateForm(); } } }); prevButton.addEventListener("click", () => { if (currentStep > 0) { currentStep--; updateForm(); } }); updateForm();