LakshmiKiran
Programmer
How do I check whether a textarea is empty? If the user does not enter any data but presses the enter key, then the form.textarea.value is not empty. How to keep a check on this?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
<script>
function checkData() {
var txtCheck = document.formName;
if(txtCheck.textarea.value == "") {
alert("Please enter information in the textarea");
txtCheck.textarea.focus();
return false;
}
}
</script>
<form name="formName" method="post" action="" onSubmit="return checkData();">
<textarea name="textarea"></textarea>
</p> <p>
<input name="Submit" type="submit" value="Submit">
</p>
</form>
<script>
function checkData() {
var txtCheck = document.formName;
if(txtCheck.textarea.value == 0) {
alert("Please enter information in the textarea");
txtCheck.textarea.focus();
return false;
}
}
</script>