Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EEP: Should Survey-to-web export format be a single-page HTML with logic handled w/ JS? #527

Closed
johnjosephhorton opened this issue May 19, 2024 · 0 comments

Comments

@johnjosephhorton
Copy link
Contributor

If users want to create a web-based version of their server, rather than make it require a server with server-side logic for advancing to questions, we could implement entirely w/ JS, making it easier for end-user to test and/or give them more flexibility.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Survey</title>
    <style>
        .question {
            display: none;
        }
        .question.active {
            display: block;
        }
        .hidden {
            display: none;
        }
    </style>
</head>
<body>
    <form id="surveyForm">
        <div id="q1" class="question active">
            <p>Question 1: What is your favorite color?</p>
            <input type="radio" name="color" value="red" id="colorRed">
            <label for="colorRed">Red</label><br>
            <input type="radio" name="color" value="blue" id="colorBlue">
            <label for="colorBlue">Blue</label><br>
            <input type="radio" name="color" value="green" id="colorGreen">
            <label for="colorGreen">Green</label><br>
            <button type="button" onclick="nextQuestion(2)">Next</button>
        </div>
        <div id="q2" class="question">
            <p>Question 2: What is your favorite animal?</p>
            <input type="radio" name="animal" value="dog" id="animalDog">
            <label for="animalDog">Dog</label><br>
            <input type="radio" name="animal" value="cat" id="animalCat">
            <label for="animalCat">Cat</label><br>
            <input type="radio" name="animal" value="bird" id="animalBird">
            <label for="animalBird">Bird</label><br>
            <button type="button" onclick="nextQuestion(3)">Next</button>
        </div>
        <div id="q3" class="question">
            <p>Question 3: Do you like pizza?</p>
            <input type="radio" name="pizza" value="yes" id="pizzaYes">
            <label for="pizzaYes">Yes</label><br>
            <input type="radio" name="pizza" value="no" id="pizzaNo">
            <label for="pizzaNo">No</label><br>
            <button type="button" onclick="nextQuestion(4)">Next</button>
        </div>
        <div id="q4" class="question hidden">
            <p>Question 4: What is your favorite pizza topping?</p>
            <input type="text" name="topping" id="topping"><br>
            <button type="button" onclick="nextQuestion(5)">Next</button>
        </div>
        <div id="q5" class="question">
            <p>Thank you for completing the survey!</p>
            <button type="submit">Submit</button>
        </div>
    </form>

    <script>
        function nextQuestion(questionNumber) {
            var currentQuestion = document.querySelector('.question.active');
            currentQuestion.classList.remove('active');
            var nextQuestion = document.getElementById('q' + questionNumber);

            // Skip logic: Show question 4 only if 'yes' is selected for question 3
            if (questionNumber === 4) {
                var pizzaAnswer = document.querySelector('input[name="pizza"]:checked');
                if (pizzaAnswer && pizzaAnswer.value === 'yes') {
                    nextQuestion.classList.remove('hidden');
                } else {
                    nextQuestion(questionNumber + 1);
                    return;
                }
            }

            nextQuestion.classList.add('active');
        }
    </script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant