Q:

how can i use setinterval on a inputfield?

i have an issue with (html) javascript and i hope someone can help me out here/
i am making my own wine cooler in javascript,
you can open and close the door, if you open the door the original temperature of 7.1 will raise with 0.9 , and after you close it it will automatically decrease to 7.1 (0.2 per 5 minutes), i used setinterval to do this.
now i want to add an inputfield input id="desiredtemp" type="text"
and another =button button type="button" id="desired">Set desired temperature /button
i did this because i want to add a function that you can lower the temperature to any temperature you want instead of the original 7.1 when you close the door. but i cant  get it working 
any help would be really appreciated.
heres my code so far
var degree = 7.2;//graden
            var counter = 0;//counter gebruikt om stand aan te geven van wijnkoeler 

            function myFunction() {
                if (counter === 0) {
                    document.getElementById("dicht").src = "images/open.jpg";
                    degree = degree + 0.9;
                    temp.innerHTML = degree; //+ " " + "graden celsius in de wijnkoeler";
                    console.log("Wijnkoeler is geopend");
                    console.log("Temperatuur " + "is " + "nu " + degree + " Graden");
                    counter = 1;
                }

                else if (counter === 1) {
                    document.getElementById("dicht").src = "images/dicht.jpg";
                    console.log("de temperatuur van de Wijnkoeler is gestegen naar" + degree);
                    console.log("De motor wordt gestart");
                    console.log("...");
                    console.log("...");
                    console.log("...");
                    var id = window.setInterval(function() {
                        degree = parseFloat(Math.max(7.2, (degree - 0.2)).toPrecision(2));//telkens 0.2 graden eraf -- afronden
                        if (degree == 7.2) {                                              //als het weer 7.2 graden is motor uitschakelen     
                            window.clearInterval(id);
                            console.log("De temperatuur is weer op " + degree + "graden" );
                            console.log("De motor wordt uitgeschakeld")
                        }
                        temp.innerHTML = degree;
                    }, 5 *60 *1000);                                                       //elke 5 minuten
                    counter = 0;
                }
            }

html: 
<body>

        <button onclick="myFunction();">Open/Close</button>
        <p id="Temperatuur">Temperatuur</p>
        <p id="temp">7.2</p>

        <input id="desiredtemp" type="text">

        <button type="button" id="desired">Set desired temperature</button> 

        <img id ="dicht" src="images/dicht.jpg"/>

    </body>

thanks again

A:

You'll need to make a few changes.  First, get rid of the constant 7.2 in your setTimeout function and replace with a variable:
var targetTemp = document.getElementById("desiredtemp").value || 7.2; //get from textbox, or use 7.2 if no value set

Then, reference it instead of the constant:
degree = parseFloat(Math.max(targetTemp, (degree - 0.2)).toPrecision(2));

and:
if (degree == targetTemp) {

Finally, you can remove the "Set desired temperature" button as you don't really need it.
You can see all of these changes in the fiddle: http://jsfiddle.net/magnafides/56w6E/3/

