DropDownList和TextBox验证

DropDownList和TextBox验证

本文介绍了DropDownList和TextBox验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助告诉如何在btn_click上TextBox5文本长度大于0时如何使警报()不弹出





I need help figurig out how I can make alert() not to popup when TextBox5 text length is greater than 0 on btn_click


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()  

推荐答案

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;
    }
}


这篇关于DropDownList和TextBox验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 13:55