DropDownList和TextBox验证 [英] DropDownList and TextBox Validation

查看:77
本文介绍了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()  

推荐答案

试试这个并根据您的需要进行调整:

Try this and adapt it to your need:
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验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆