I have a javascript:
<script>
function updatecode() {
var widthError = "<span style='color:#ff0000'>Error</span>";
var width = document.getElementById('width').value;
if(width < 300) {
document.getElementById('error_width').innerHTML = widthError;
}else {
document.getElementById('error_width').style.visibility = "hidden";
}
}
</script>
<input type="text" name="width" id="width" value="auto" onchange="updatecode()" />
<span id="error_width"></span>
When I enter width = 400, it is ok. And when I enter width = 200, it does not show the error message. How can I fix that?
Why
Let’s first take a look at the code:
This will happen if it is bigger than 400 right? And when it goes down to 200, its
visibilityis still hidden. That’s why it doesn’t show up.Fixing it
Make it visible will fix it.
and actually you don’t need to hide it because it doesn’t have anything it it when the
widthis bigger than300.And…
You might want to change this
to this:
Hope this help you out.
Demo: http://jsfiddle.net/DerekL/yW8wt/