Click here to Skip to main content
15,029,596 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a dropdown list, with an "other" item in it. When a user clicks this option,
text box will enable . how to set validation in this text box
Posted

1 solution

Simply by checking for it's disability. If it is disabled then skip validation else force to check.
Example:
JavaScript
function validateControls()
{
  var txt=document.getElementById("<=txtboxName.ClientID%>");
  if(txt.disabled==false)
  {
    if(txt.value.trim()=="")
    {
        //alert msg
        return false;
    }
    else
    {
       return true;
    }
  }
}

Or,
Checking for the dropdownlist selected value.
Example:
JavaScript
function validateControls()
{
  var drp=document.getElementById("<%=drpName.ClientID%>");
    if(drp.value.trim()=="Other")
    {
        //alert msg
        return false;
    }
    else
    {
       return true;
    }
}

Hope, it helps :)
   
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900