Sample:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Check Text Field Value</title>
<style>
</style>
</head>
<body>
<textarea rows="5" cols="35" id="field" oninput="indicate();"></textarea>
<div id="indicator"></div>
<script>
function indicate() {
var field = document.getElementById('field');
var indicator = document.getElementById('indicator');
if (field.value) {
indicator.innerHTML = 'Some content';
} else {
indicator.innerHTML = 'No content';
}
}
indicate();
</script>
</body>
</html>
Demo: http://jsfiddle.net/RainLover/eZaRd/
I want to check if the text field is empty or not. I've seen many questions and answers some using if (textarea.value)
and some using if (textarea.value != "")
. Or the following pair:
if (!textarea.value)
vs. if (textarea.value == "")
.
I wonder what's the difference between them.