kramann.info
© Guido Kramann

Login: Passwort:










kramann.info
© Guido Kramann

Login: Passwort:




Hörtest-Anwendung in Javascript - Schalter

(EN google-translate)

(PL google-translate)

Nun wird ein Schalter ergänzt, der zum Ein- und Ausschalten der Anwendung dienen soll. Beim ersten Betätigen soll auch ein Audiokanal erzeugt werden, an den die Samplewerte der Sinusschwingung geschickt werden.


<!DOCTYPE html>
<html>
    <head lang="de">
        <meta charset="iso-8859-1">
         <script language:javascript>
            var frequenz = 440;
            var amplitude = 0;

            var zustand = -1; //-1: vor erstem Start, 1: nach erstem Start, 0: nach erstem Stop.

            function setzeFrequenz()
            {
                frequenz = document.getElementById("input_frequenz").value;
                document.getElementById("wert_frequenz").innerHTML = frequenz;
            }
            function setzeAmplitude()
            {
                amplitude = document.getElementById("input_amplitude").value;
                document.getElementById("wert_amplitude").innerHTML = amplitude;
            }

            function startstop()
            {
                if(zustand==-1)
                {
                    document.getElementById("startstop").value = "AN";
                    document.getElementById("startstop").style.backgroundColor = "#00FF00";
                    zustand = 1;
                }
                else if(zustand==1)
                {
                    document.getElementById("startstop").value = "AUS";
                    document.getElementById("startstop").style.backgroundColor = "#FF0000";
                    zustand = 0;
                }
                else //if(zustand==0)
                {
                    document.getElementById("startstop").value = "AN";
                    document.getElementById("startstop").style.backgroundColor = "#00FF00";
                    zustand = 1;
                }
            }

        </script>
    </head>
    <body>
        <fieldset>
            <p>
                <label>Frequenz: 
                    <input style="width:400px;" id="input_frequenz"  type="range" min="1" max="20000" value="440" onmousemove="javascript:setzeFrequenz()" />
                <span id="wert_frequenz">440</span>Hz</label>
            </p>
            <br/>
            <p>
                <label>Amplitude: 
                    <input style="width:400px;" id="input_amplitude"  type="range" min="0" max="1000" value="0" onmousemove="javascript:setzeAmplitude()" />
                <span id="wert_amplitude">0</span></label>
            </p>
            <p>
                <input id="startstop" type="button" value="AUS" style="background-color: #FF0000" onclick="javascript:startstop()"/>
            </p>
        </fieldset>
    </body>
</html>

Code 0-1: Quelltext.