Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You call the function wr_hours(); only once... with the onclick budilnik is called, but that doesn't touch wr_hours again. The first time the code is run, because the page is loaded, but after that, with the onclick only the values of min and hour are set again.</p> <p>edit: you shouldn't call your form "alert", since that's a reserved word in javascript, same for the variable min. also: the variables min and hour are defined in the function <code>budilnik</code>, but they're not known outside this scope. I also renamed the variable <code>budilnik</code> to a global variable <code>justonce</code> to make sure you can check it outside the scope of <code>budilnik</code>. I rewrote your code a bit:</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;div&gt; &lt;form name="frm"&gt; &lt;input type="text" name="hour" /&gt; &lt;input type="text" name="mins"/&gt; &lt;input type="button" value="ok" onclick="justonce=1;"&gt; &lt;/form&gt; &lt;font color=#660000 size=20 face=Tahoma&gt;&lt;span id="hours"&gt;&lt;/span&gt;&lt;/font&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; &lt;script type="text/javascript"&gt; obj_hours=document.getElementById("hours"); justonce=0; function wr_hours() { time=new Date(); time_min=time.getMinutes(); time_hours=time.getHours(); time_wr=((time_hours&lt;10)?"0":"")+time_hours; time_wr+=":"; time_wr+=((time_min&lt;10)?"0":"")+time_min; obj_hours.innerHTML=time_wr; if (justonce==1 &amp;&amp; frm.mins.value==time_min &amp;&amp; frm.hour.value==time_hours) { alert('welldone'); justonce=0; } } setInterval("wr_hours();",1000); &lt;/script&gt; </code></pre> <p>Your function wr_hours could be a lot shorter by the way:</p> <pre><code>function wr_hours() { time=new Date(); obj_hours.innerHTML=("%02d",time.getHours())+":"+("%02d",time.getMinutes()); if (justonce==1 &amp;&amp; frm.mins.value==time.getMinutes() &amp;&amp; frm.hour.value==time.getHours()) { alert('welldone'); justonce=0; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload