<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$('#action').click(function() {
if (!$.trim($("#txtarea").val())) {
alert("please input something"); //to check textarea is empty or not
}
});
</script>
Above JQuery code will check that textarea is empty or not it will also check white space.
Complete example is given below-
<!DOCTYPE html>
<html>
<body>
<center>
<textarea cols="50" rows="8" id="txtarea" required></textarea>
<br>
<button id="action">Click to check</button>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$('#action').click(function() {
if (!$.trim($("#txtarea").val())) {
alert("please input something"); //to check textarea is empty or contains only white-space
}
});
</script>
</center>
</body>
</html>
No comments:
Post a Comment