Try this
1) Call a function when input value changes use onchange or blur any one event
2) set div id equal to hotapp3
Method 1
<head> <script> function checkValue(){ let value = document.getElementById('ref3').value; if (value == 2) { document.getElementById('hotapp3').style.visibility = 'visible'; } else { document.getElementById('hotapp3').style.visibility = 'hidden'; } } </script> </head> <body> <form name="myform"> <div><input type="text" id="ref3" value="" onchange="checkValue()"></div> <div id="hotapp3" style="visibility:hidden"> <label>Show me</label> </div> </form> </body> </html>
Method 2
You can also do few changes pass input text value directly to function at the time of calling like this
onchange="test(this.value)
<input type="text" id="ref3" value="" onchange="test(this.value)">
and can use it directly in function
function test(value){ if (value == 2) { document.getElementById('hotapp3').style.visibility = 'visible'; } else { document.getElementById('hotapp3').style.visibility = 'hidden'; } }
As commented by you if you want to do same for default value than call this function on page relode
window.onload = function() { checkValue(); };