how to make sure that the value in a dynamic textbox is not empty using javascript
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.
精彩评论