I have the following code with following conditions:
- A value less than 60 seconds is fast
- A value more than 60 seconds is slow
- Must fill out both input fields to show "fast" or "slow"
My only problem is that the code interprets 0
as null
. So, If I put 1 minutes 0 seconds, then nothing shows.
I want it to show "fast" when I enter 1 minute 0 seconds.
Thanks in advance.
<html>
<head>
<script type="text/javascript" src="//code.jquery.com/jquery-1.9.1.js"></script>
<!-- TODO: Missing CoffeeScript 2 -->
<script type="text/javascript">//<![CDATA[
$(window).load(function(){
$('input').keyup(function(){
var min = 60 * Number($('#D').val());
var sec = Number($('#E').val());
if ((min+sec) <= 60) {document.getElementById("Run").innerHTML = "Fast";}
if ((min+sec) >= 61) {document.getElementById("Run").innerHTML = "Slow";}
if (min == null | min == "") {document.getElementById("Run").innerHTML = "";}
if (sec == null | sec == "") {document.getElementById("Run").innerHTML = "";}
});
});
</script>
<style>
h1 { margin: 0 10px 25px 5px; padding: 5px; font-size: 32px; font-family: Arial }
input { margin: 0 10px 10px 10px; padding: 5px; font-size: 24px; width: 200px }
label { margin: 0 10px 10px 10px; font-size: 20px; display: block; font-family: Arial }
span { margin: 0 0px 0px 10px; font-size: 44px; font-family: Arial }
stat { margin: 0 0px 0px 10px; font-size: 24px; font-family: Arial }
</style>
</head>
<body>
<input id="D"
type="number"
class="form-control formBlock"
placeholder="Minutes"
required=""
min="1"
max="59"
onkeyup="if(parseInt(this.value) > 59){ this.value = 59; return false; }"
>
<stat id="Run"></stat><br>
<input id="E"
type="number"
class="form-control formBlock"
placeholder="Seconds"
required=""
min="1"
max="59"
onkeyup="if(parseInt(this.value) > 59){ this.value = 59; return false; }"
>
<br>
<br>
<script>
// results
if (window.parent && window.parent.parent){
window.parent.parent.postMessage(["resultsFrame", {
height: document.body.getBoundingClientRect().height,
slug: ""
}], "*")
}
window.name = "result"
//
</script>
</body>
</html>