0

I am trying to create a kind of survey with 26 questions and want the shown question (saved in a div) to change when the proceed button is clicked. I have tried several things now but nothing worked out for me. I can't use JQuery because the final product has to work in IE7 and I am a beginner in terms of programming so I am kind of stuck here.

For further information's please take a look at my code, I know having JS in the html file isn't that great but for this small bit of code I think its OK. At the moment I am only able to switch in between two questions how do I get the ability to add more than 2 questions?

HTML with script at the end:

<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
    <link rel="stylesheet" href="css/style.css">
</head>

<body>
    <div class="form-wrapper">
        <h1>Wie sehr (oder oft) wurden Sie in den letzten ZWEI Wochen von den folgenden Problmen belastet?</h1>
        <br>
        <br>         <!-- QUESTIONS -->
        <div id="Frage1" class="frage" style="display:block">1: Wenig Interesse oder Freude an Dingen und Aktivitäten.</div>
        <div id="Frage2" class="frage" style="display:none">2: Sich niedergeschlagen, depressiv oder hoffnungslos fühlen. </div> 
        <div id="Frage3" class="frage" style="display:none">3: Sich reizbarer, mürrischer oder ärgerlicher als gewöhnlich fühlen.</div>
        <br>                      <!-- ANSWER BUTTONS -->
        <form action="">
            <form class="form">
                <br>
                <section>
                    <div>
                        <input type="radio" id="control_01" name="select" value="0">
                        <label for="control_01">
                            <h2>Garnicht</h2>
                            <p>überhaupt nicht.</p>
                        </label>
                    </div>
                    <div>
                        <input type="radio" id="control_02" name="select" value="1">
                        <label for="control_02">
                            <h2>Kaum</h2>
                            <p>selten, an weniger als 1-2 Tagen</p>
                        </label>
                    </div>
                    <div>
                        <input type="radio" id="control_03" name="select" value="2">
                        <label for="control_03">
                            <h2>Leicht</h2>
                            <p>an mehreren Tagen.</p>
                        </label>
                    </div>
                    <div>
                        <input type="radio" id="control_04" name="select" value="3">
                        <label for="control_04">
                            <h2>Mittel</h2>
                            <p>An mehr als der Hälfte der Tage.</p>
                        </label>
                    </div>
                    <div>
                        <input type="radio" id="control_05" name="select" value="4">
                        <label for="control_05">
                            <h2>Stark</h2>
                            <p>An fast jedem Tag.</p>
                        </label>
                    </div>
                    <div>
                        <input type="radio" id="control_06" name="select" value="">
                        <label for="control_06">
                            <h2>KA</h2>
                            <p>Das möchte ich nicht beantworten.</p>
                        </label>
                    </div>
                </section>
                <button id="weiter" class="Weiter" name="submit" onclick="auswertung();replace();return false">Weiter</button>
            </form>
    </div>
    <!-- Wrapper ende -->
    <script>     <!-- change question script that needs to be reworked -->
        function replace() {
            document.getElementById("Frage1").style.display = "none";
            document.getElementById("Frage2").style.display = "block";
            document.getElementById("Frage3").style.display = "none";
        } 
    </script>

    <script>
        function auswertung() {
            var radios = document.getElementsByName('select');

            for (var i = 0, length = radios.length; i < length; i++) {
                if (radios[i].checked) {
                    // wohin der wert geschrieben wird
                    alert(radios[i].value);

                    break;
                }
            }
        }
    </script>
</body>

</html>
Suresh Ponnukalai
  • 13,820
  • 5
  • 34
  • 54
  • use javascript https://developer.mozilla.org/en-US/docs/Learn/JavaScript and you can use jquery too, https://stackoverflow.com/questions/20319009/json-and-jquery-still-undefined-in-internet-explorer-7-and-8 – Anil Nov 07 '17 at 09:19
  • 1
    just for curiosity, why support IE7 in 2017? – Lorenzo Marcon Nov 07 '17 at 09:25
  • "I can't use JQuery because the final product has to work in IE7 ". jQuery 1.x branch supports IE6, 7, and 8. See https://jquery.com/browser-support/: "_If you need to support older browsers like Internet Explorer 6-8, Opera 12.1x or Safari 5.1+, use jQuery 1.12._" – ADyson Nov 07 '17 at 09:29
  • @Lorenzo I dont know why the company where i do my education still uses IE7 i just have to deal with it ¯\_(ツ)_/¯ – MockingSniper Nov 07 '17 at 09:37
  • 1
    @ADyson thanks for the hint iam gonna try it with jquery again :) – MockingSniper Nov 07 '17 at 09:40

0 Answers0