3

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>
2
  • 1) please state your question clearly 2) please post your markup Commented May 11, 2012 at 3:19
  • Hi NiftyDude - I am trying to validate using validation engine from position-absolute.com/category/javascript. Commented May 11, 2012 at 3:37

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.