空搜索条件消息不起作用

时间:2016-11-02 08:38:11

标签: javascript asp.net

以下java脚本是提示弹出消息,

function TrimString(sInString) {
    sInString = sInString.replace(/^\s+/g, ""); // strip leading
    return sInString.replace(/\s+$/g, ""); // strip trailing
}
function ValidateEmptyCriteria(form) {

    var bolAllEmpty = true;`enter code here`
    for (var i = 0; i < form.length; i++) {
        // alert(i);
        //alert(form.elements[i].type); 
        if (form.elements[i].type == 'text') {
            if (TrimString(form.elements[i].value) != "") {
                bolAllEmpty = false;
                break;
            }
        }
        if (form.elements[i].type == 'select-one') {
            if (form.elements[i].selectedIndex > 0) {
                bolAllEmpty = false;
                break;
            }
        }

        if (form.elements[i].type == 'checkbox') {
            if ((form.elements[i].checked) == true) {
                bolAllEmpty = false;
                break;
            }
        }
        
    }

    if (bolAllEmpty) {
        return ConfirmEmptyCriteriaSearch();
    }
    else return (true);
}

function ConfirmEmptyCriteriaSearch() {
    var agree = confirm("No search string is entered. Click [0K] to show all records.");

    if (agree)
        return true;
    else
        return false;
}

function ValidateEmptyCriteriaExcludeDate(form) {
    var bolAllEmpty = true;
    for (var i = 0; i < form.length; i++) {
        // alert(i);
        //alert(form.elements[i].type); 
        if (form.elements[i].type == 'text') {
            if (TrimString(form.elements[i].value) != "" && form.elements[i].id != 'txtFromDate' && form.elements[i].id != 'txtToDate') {
                bolAllEmpty = false;
                break;
            }
        }
        if (form.elements[i].type == 'select-one') {
            if (form.elements[i].selectedIndex > 0) {
                bolAllEmpty = false;
                break;
            }
        }
    }

    if (bolAllEmpty) {
        return ConfirmEmptyCriteriaSearch();
    }
    else return (true);
}

  • 然后我使用下面的代码将函数调用到页面。

<script language="javascript" type="text/javascript" src="<%=Page.ResolveUrl("~/Control/ValidateEmptyCriteria.js")%>"></script> 

以下是按钮代码,

<table cellpadding="0" cellspacing="0" border="0" width="100%">
                                                                <tr class="clsTBRow" style="height: 8px;">
                                                                    <td style="width: 10px;" />
                                                                    <td style="width: 150px;" />
                                                                    <td />
                                                                </tr>
                                                                <tr class="clsTBRow">
                                                                    <td>
                                                                        &nbsp;
                                                                    </td>
                                                                    <td>
                                                                        Card Type Name :
                                                                    </td>
                                                                    <td>
                                                                        <asp:TextBox ID="txtCardTypeName" runat="server" MaxLength="50" Width="200px" />
                                                                    </td>
                                                                </tr>
                                                                <tr class="clsTBRow">
                                                                    <td>
                                                                        &nbsp;
                                                                    </td>
                                                                    <td>
                                                                        Description :
                                                                    </td>
                                                                    <td>
                                                                        <asp:TextBox ID="txtDescription" runat="server" Width="200px" MaxLength="100" />
                                                                    </td>
                                                                </tr>
                                                                <tr class="clsTBRow" style="height: 50px; vertical-align: middle;">
                                                                    <td colspan="2">
                                                                        &nbsp;
                                                                    </td>
                                                                    <td>
                                                                        <span id="spanCmdSubmit" runat="server">
                                                                            <asp:Button ID="CmdSubmit" runat="server" Text="Search" />&nbsp;</span> <span id="spanCmdReset"
                                                                                runat="server">
                                                                                <asp:Button ID="CmdReset" runat="server" Text="Reset" /></span>
                                                                    </td>
                                                                </tr>
                                                            </table>

  • 问题是它不起作用。我能解决这个问题的任何帮助吗?
  • 我需要的是当我的文本框为空并且我点击搜索时,它应该提示我在java脚本中声明的弹出消息。

0 个答案:

没有答案