check empty textraea or field

check empty textraea or field

by Adi Jaya

HTML

<textarea id="area"></textarea>
<p>status : <i id="status"></i></p>
<button id="mybutton">Check</button>

<!-- without jQuery -->
<button onclick="checkTextarea()">check without jQuery</button>

CSS

body {
  margin : 0 auto;
  padding :20px;
  font-family : arial;
}

textarea {
    width: 100%;
    height: 100px;
    resize: none;
}

p {
    margin-bottom: 15px;
    color: #e05856;
}
i {
    color: #107928;
}

JavaScript

function checkTextarea() {
	var content = $("#area").val();
	if(content.length<1){
  	/* alert ("Textarea can't be left empty"); */
    document.getElementById("status").textContent = "Textarea can't be left empty";    
		return true;
   }
   else{
		document.getElementById("status").textContent = "OK";
		return false;
   }
}


//call with jQuery
$("#mybutton").click(function(){
	checkTextarea();
});