0

In the aspx page in asp.net, There is multiple text box.

Like--> Name E-mail Id EmployeeCode

   Text Box1                    Text Box2                          Text Box3

   Text Box4                    Text Box5                           Text Box6

   Text Box7                    Text Box8                          Text Box9

Now I need validation on the text box1,Text Box2 ,Text Box3,at least one of the text box is filled,either with asp.net validation or with java script

user988595
  • 41
  • 1
  • 1
  • 7
  • Try this post which is very similar http://stackoverflow.com/questions/3915994/asp-net-required-field-validator-for-at-least-one-textbox-contains-text – Conrad Lotz Sep 14 '12 at 06:11

2 Answers2

0

Lets say Id of ur textboxs is txt1, txt2 and txt3, then u can do it like

  function validate()
  {
      var txt1Value = document.getElementById("<%=txt1.ClientID%>").value;
      var txt2Value = document.getElementById("<%=txt2.ClientID%>").value;
      var txt3Value = document.getElementById("<%=txt3.ClientID%>").value;
      if(txt1Value != "" || txt2Value != "" || txt3Value != "")
      {
            return true;
      }
      return false;
  }

U can also use trim(), mentioned below

function trim(s)
{
    return rtrim(ltrim(s));
}

function ltrim(s)
{
    var l=0;
    while(l < s.length && s[l] == ' ')
    {   l++; }
    return s.substring(l, s.length);
}

function rtrim(s)
{
    var r=s.length -1;
    while(r > 0 && s[r] == ' ')
    {   r-=1;   }
    return s.substring(0, r+1);
}
Developer
  • 759
  • 2
  • 9
  • 24
0

Use this.

<script type="text/javascript">
var oneFilled = false;
for(var a = 0 ; a < 3 ; a ++)
{
    if($('input').eq(a).val() != "")
    oneFilled = true
}
return oneFilled;
</script>
Taha Rehman Siddiqui
  • 2,441
  • 5
  • 32
  • 58