I am trying to make a small javascript program in which I have a Div that is transparent initially, and contains an editbox inside. But I want that transparent div to become pink if the text inside editbox is not number. How can I do this? I tried something like this but nothing works:
function proz(){
var textbox = document.getElementById("nr").value; / nr is editbox
var div = document.getElementById("proz"); / proz is the transparent div
if (document.getElementById("nr").value == "a"){ / i tried with if var == "a" but nothing.
div.setAtribute("id", "proz2"); /here proz 2 is another pink div, trying to overlay first div
}
}
I am trying with only letter "a" instead of numbers to check if anything works at least... So any advices please. Thank you!
Later Edit: HTML part:
<body>
<div class="patratpunctat">
<h1><center> Panou centrat </center></h1>
<p> Acest panou va fi centrat vertical si orizontal in pagina.</p>
<div class="pportocaliu">
<div class="prosualbastru"> </div>
</div>
<!-- -->
<!-- partea pentru patratul roz cu javascript-->
<div class="proz">
<div class="inputt">
<input type="text" placeholder="Numar interg" name="nrintreg">
</div>
<script>
function check(){
var textbox = document.getElementById("nrintreg").value;
if (document.getElementById("nrintreg").value == "a"){
window.alert('omg')
}
}
</script>
</div>
</div>
</body>
And yes, I am trying to make it instantly. Like if there is something else than a number there, to make the div pink. if it is Number, div remains transparent.