Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I need help figurig out how I can make alert() not to popup when TextBox5 text length is greater than 0 on btn_click


JavaScript
function Validate()
            {
                 
                if (document.getElementById("<%=ddlFinalAction.ClientID%>").selectedIndex == "")
                {
                    alert('Must Enter Final Action Taken');
                    return false;
                }
                 
 
                if (document.getElementById("<%=ddlFinalAction.ClientID%>").selectedIndex == "1" || document.getElementByID"<%TextBox5.ClientID%>". value > 0)
                {
                    alert('Must Enter Comment');
                    return false;
                     
                }
 
                
                 
                return true;
           }//end validate()  
Posted

1 solution

Try this and adapt it to your need:
C#
function Validate()
{
    var message = "";
    var ddl = document.getElementById("<%= ddlFinalAction.ClientID %>");
    var ddlValue = ddl.options[ddl.selectedIndex].value;

    if (ddlValue == "")
    {
        message +="Must Enter Final Action Taken\n";
    }

    var txt = document.getElementById("<%= TextBox5.ClientID %>");
    var txtValue = txt.value.trim();
    if (txtValue.length == 0)
    {
       message +="Must Enter Comment";
    }

    if(message != "")
    {
        alert(message);
        return false;
    }
    else
    {
        alert("ok");
        return true;
    }
}
 
Share this answer
 
v2

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