Javascript validation for multiple textboxes

前端 未结 4 1246
故里飘歌
故里飘歌 2021-01-24 07:12

I am having some trouble figuring out how to validate my textboxes using js. I have 10 textboxes, the user can fill out any number 1-10, but cant fill out 0. Here is the js th

4条回答
  •  爱一瞬间的悲伤
    2021-01-24 07:41

    you can use jquery. add common class name for all your textboxes i.e.

    
    

    now in js function

    function submit()
    {
            $('.student').each(function() {
               if($(this).val() == '' || $(this).val() == null)
               {
                    // your error message
                    return false;
               }
    
           }
    }
    

    this function check all the elements with student class.

提交回复
热议问题