3

我有一个复选框和一个文本框。我要求,如果勾选了复选框,则文本框变为必填项。反之亦然,如果文本框已填满,则复选框变为必填项。

所以样本是

项目名称 - 复选框 - 到期日期 项目名称 2 - 复选框 2 - 到期日期 2

使用查询从数组中的数据库获取数据。

我的代码看起来像

<script type="text/javascript"> 
$(document).ready(function(){
    $("#sea").validationEngine();
   });

function industry(field, rules, i, options) {    
var atLeastOneIsChecked = $('input[name="extraqualification[]"]:checked').length > 0;
if (atLeastOneIsChecked == 1 )        {
if(document.getElementById('extraqualificationexpirydate<?php echo $extraqual['Id']?>').value=='')
{
   return "Please supply a certificate expiry";
}else{} }
    } </script>
4

1 回答 1

2

您需要有条件的必需验证。您可以使用如下condRequired方法:

<input value="" type="text" name="test" id="test" />
<input class="validate[condRequired[test]]" type="text" id="test_2" name="test_2"/>

另外,请确保您使用的是 2.6 或更高版本。

于 2012-12-29T12:36:46.990 回答