English 中文(简体)
多个检查箱验证
原标题:Multiple check box validation

我知道如何验证单一检查箱,但如果我有多个检查箱,我将把这些价值保留在我数据库中的一个阵列? 我想用户要么选择一个或多个检查箱,安装一个警示箱。

下面是表格的分号,验证人一使用。 其余表格证明是罚款。 我用灰色生产多个检查箱,但中途拖.却显示,因此,让你知道有不止一个箱子。

传真:

<input type="checkbox" name="j" value="<%=getcall_1_ary(jt)%>"/>

Javascript:

 if (document.addSC.j.checked == false ) {
   alert("Select Desired Job Type")
 }
最佳回答

引证该法典。

<script>
    function validateCheckBoxes() 
    {
        var isValid = false;
        //alert("Check if any checkbox is not checked..."); 
        var allRows = document.getElementsByTagName("input");
        for (var i=0; i < allRows.length; i++) {
            if (allRows[i].type ==  checkbox  && allRows[i].name ==  123 ) {
                if (allRows[i].checked == true) {
                       return true;
                }
            }
        }
        return isValid;
    }

    function submitBtn (){
        if (!validateCheckBoxes()){
            alert("no check box selected");
        }
        else 
            alert("one or more check box selected");
    }


</script>

传真 部分:

<form  method="get">
    <input type="checkbox" name="123" />
    <input type="checkbox" name="123" />
    <input type="checkbox" name="123" />
    <input type="button" value="submit" onClick="JavaScript:submitBtn();"/>
</form>

现在检查。

问题回答

我建议,你利用JQuery来盘问检查箱,然后就检查箱,以确保至少检查一次。

Well, first of all, DO VALIDATE YOUR INPUT DATA SERVER-SIDE. I read your question and it suggests that you don t, so this is my tip.

此外,你还可以获得所有带有“j”名称的检查箱。

var checkboxes = document.getElementsByTagName("input");
var jChecks = [];
for (var i = 0; i <= checkboxes.length; i++) {
    if (checkboxes[i].name == "j" && checkbox[i].checked) {
        jChecks.push( checkboxes[i] );
    }
}
if (jChecks.length > 0) {
    alert( more then one selected! );
} else {
    alert( select some checkboxes! );
}




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签