in my project i have 100 textbox i want to check the every text-box is empty or not
my problem is can i write a short code to check the every textbox is empty or not
my code is so lengthy becoz i check every textbox in if condition
please help me
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jaish MathewsRank #225 · 11K reputationPosted Apr 1, 2010, 8:51 AM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Apr 1, 2010, 10:44 AM EDT
Dharmesh SharmaRank #1,974 · 741 reputationPosted Apr 1, 2010, 10:05 PM EDT
and somthing 200 textbox in the web form how to check the every textbox is empty and enter value is numeric
how to use the control collection
pleas help me........
thanks
Nikhil Mahajan20 reputationPosted Apr 2, 2010, 3:01 AM EDT
with single for loop it would be checked
Jaish MathewsRank #225 · 11K reputationPosted Apr 2, 2010, 9:24 AM EDT
Should approach with JS, as
So you decided to do validation through JavaScrit. Below is one sample. Call this before any postback. I used a regular expression for validating the numeric entry. Remaing all self explanatory.
function validateTextBoxEntries() {
var elements = document.getElementsByTagName("input");
//alert(elements.length);
for (var i = 0; i < elements.length; i++) {
if (elements[i].type.match(/text/)) {
if(elements[i].value == '' || !isNumeric(elements[i].value))
{
alert(elements[i].value + " Invalid");
}
}
}
}
function isNumeric(val) {
var reg = /^ *[0-9]+ *$/;
return reg.test(val);
}