开发者

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());
      }
    });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜