show a div message if a value is less than another value in javascript

i want to make a div shows if a value of an input less than 1000 and hide this div if the value is greater or equal 1000 in a real time in JavaScript

Upvotes: 0

Views: 532

Answers (2)

westdabestdb
westdabestdb

Reputation: 4648

let input = document.querySelector("#number")
let box = document.querySelector(".box")

update = () => {
let value = input.value
if(parseInt(value) < 1000){
	box.style.display = "none"
} else {
	box.style.display = "block"
}
setTimeout(update, 1000);
}

update()
.box {
	height: 100px;
	width: 100px;
	background-color: lime;
}
<input type="text" id="number" />

<div class="box">
</div>

Upvotes: 1

Umid Kurbanov
Umid Kurbanov

Reputation: 184

Maybe this can help:

<input type="text" id="myinput">
<button onclick="checkValue()">Enter</button>

<div id="divmsg">
</div>

<script>
    function checkValue()
    {
        var num = parseInt($("#myinput").val());
        if (num > 1000)
        {
            $("#divmsg").hide();
        }
        else
        {
            $("#divmsg").text(num);
        }
    }
</script>

Upvotes: 0

Related Questions