开发者

how to make sure that the value in a dynamic textbox is not empty using javascript

开发者 https://www.devze.com 2023-02-26 07:28 出处:网络
I have nearly 80 textbox controls being created dynamically on the change of a dropdownlist item. I need to make sure that none of these textboxes 开发者_Go百科are empty when the user clicks on add i

I have nearly 80 textbox controls being created dynamically on the change of a dropdownlist item.

I need to make sure that none of these textboxes 开发者_Go百科are empty when the user clicks on add item button.

I am aware of document.getElementbyid , however it does not serve my purpose as I will not know the id of the textboxes. The ids of the textboxes created start with "txt".

Can anyone paste a sample code of how to achieve this.

Thanks in advance.


function validateInput() {
     var inputControls = document.getElementsByTagName("input");
     for(var i = 0; i < inputControls.length; i++) {
          var c = inputControls[i];
          if(c.id && c.id.substring(0, 3) === 'txt' && c.value === '') return false;
     }
     return true;
}

Attach this to the submit handler or whatever appropriate handler.

0

精彩评论

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

关注公众号