当前位置: 代码迷 >> Web前端 >> checkbox多选框运用实例说明
  详细解决方案

checkbox多选框运用实例说明

热度:79   发布时间:2012-11-23 00:03:43.0
checkbox多选框使用实例说明
js代码
<script language="javascript">
   var len = document.customerForm.yangshu.length;
   var checked = false;

   for (i = 0; i < len; i++)
   {
      if (document.customerForm.yangshu[i].checked == true)
      {
          checked = true;
          break;
       }
    }
    if (!checked)
    {
        alert("请至少选择一个双氧度数!");
        return false;
    }    
</script>  

form内容:
<form name="customerForm" onsubmit="return check()" method="post">
<table>
    <tr>
<td height="25" bgcolor="#FFFFFF">
<div align="center" class="STYLE1">
双氧度数
</div>
</td>
<td height="25" bgcolor="#FFFFFF" class="STYLE2 STYLE1">
<input type="checkbox" name="yangshu" value="1">
3%
<input type="checkbox" name="yangshu" value="2">
6%
<input type="checkbox" name="yangshu" value="3">
9%
<input type="checkbox" name="yangshu" value="4">
12%
</td>
</tr>
<input type="submit" name="Submit" value="提交">
</table>
</form>

接收处理页面:
jsp代码:
String[] xiangmu = request.getParameterValues("xiangmu");
if (xiangmu != null && !xiangmu.equals("")) {
for (int i = 0; i < xiangmu.length; i++) {

if (xiangmu[i].equalsIgnoreCase("1"))
ju = "1";
if (xiangmu[i].equalsIgnoreCase("2"))
ran = "2";
if (xiangmu[i].equalsIgnoreCase("3"))
tang = "3";
if (xiangmu[i].equalsIgnoreCase("4"))
washcut = "4";

}

}
  相关解决方案