Validation for the more elements which is in div block after checked one checkbox only
I am working in PHP using codeigniter framework, My question is actually i want to implement the one functionality as like the there are four checkboxes while click on one checkbox there is div open which contain three other fields which are the required so validation is applicable to only that field and while we checked to other anycheckbox there is another div open and also validation is applicable to that div only when it is open so plz guide me for this i want jquery validation
Here is sample code
if($('#exactplate').attr('checked','checked'))
{
$('#exact_plate').show();
}else
{
$('#exact_plate').hide();
}
});
My html
<li class="sctionbr">
<label> Exact number plate</label>
<div class="fl">
<input type="checkbox" name="exactplate" id="exactplate" value="yes" class="txtbox2" onchange="exactPlate()" /><br/>
</div>
</li>
open div after checked
<div style="display:none;" id="exact_plate" >
<li>
<label><span class="red">*</span> Exact number plate</label>
<div class="fl">
<input type="text" name="description3" id="description3" re开发者_如何学JAVAadonly="true" value="<?php echo $result->plate_title;?>" class="txtbox2" /><br/>
</div>
</li>
<?}?>
<li>
<label><span class="red">*</span> Price</label>
<div class="fl">
<input type="text" name="budget3" id="budget3" alt="ch" value="<?php echo set_value('budget3')?>" class="txtbox2" /> £<br/>
<?php if(form_error('budget3')) { echo form_error('budget3'); }?>
</div>
</li>
<li>
<label><span class="red">*</span> Estimated delivery time</label>
<div class="fl">
<input type="text" alt="number" name="period3" id="period3" value="<?php echo set_value('period3')?>" class="txtbox2" /> Days<br/>
<?php if(form_error('period3')) { echo form_error('period3'); }?>
</div>
</li>
<li class="sctionbr"> </li>
</div>
If I am understanding correctly, you want to display div#exact_plate only when input#exactplate is checked. If that is so, use the following code:
$(document).ready(function () {
$("#exactplate").change(function () {
if ($(this).is(":checked")) {
$("#exact_plate").show();
} else {
$("#exact_plate").hide();
}
});
});
The evaluation of $("#exactplate").is(":checked") will provide you a boolean indicating if validation rules should be applied in any validation routine you perform during form submission, i.e.:
$(document).ready(function () {
...
$(form).submit(function (e) {
var isValid = true;
if ($("#exactplate").is(":checked")) {
// TODO: Validation methods for fields in div#exact_plate
}
if (!isValid) {
e.preventDefault();
// TODO: User reprompt
}
});
});
精彩评论