Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

conditional validation in jquery validation engine

I have a checkbox and a textbox. I require that if a checkbox is ticked then textbox becomes compulsary. Vice versa if the textbox is filled the checkbox becomes compulsary.

So sample would be

Name of Item - Checkbox - Expiry Date Name of Item2 - Checkbox2 - Expiry Date2

Data is fetched from the database in the array using a query.

My code looks like

<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>
like image 897
Sam Avatar asked May 22 '26 22:05

Sam


1 Answers

You need conditional required validation. There is a condRequired method that you can use as follows:

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

Also, make sure you are using version 2.6 or above.

like image 200
Amyth Avatar answered May 25 '26 13:05

Amyth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!