How to display an error if the content of a <textarea></textarea> is empty using javascript?
I know ho开发者_JAVA技巧w to display an error message if the user leaves a required input field blank when filling in a form, but I am not able to do the same with the textarea.
i think on change fires for text areas as well so assuming it does
theTextArea.onChange = function(){
if(this.value == ''){
alert('You must supply a value for this field');
}
};
or with jquery
$(document).ready(
function(){
$('#mytextarea').change(function(){
var $this = $(this);
if($this.val() == ''){
alert('You must supply a value for this '+$("label[for='mytextarea']").text());
}
});
});
精彩评论