Reputation: 76
Yii- show/hide div based on radio selection. it's working fine. but in that div required fields are there. after page refresh(if any mandatory fields not fulfill) the div is not showing.
$(function() {
$("#placed").hide();
$(document).on('click', 'input:radio[name*="PlacementInfo[status]"]', function() {
if ($(this).attr('id') == 'PlacementInfo_status_0') {
$('#placed').show();
} else {
$('#placed').hide();
}
});});
• I'm not using radio button checked property on page load.
• I'm using yii-scenario(for required fields)
array('organization,role,joiningdate,location,salary,completedyear', 'required','on'=>'checked'),
Upvotes: 1
Views: 432
Reputation: 414
you need to determine the status on page load also. Try
$(function () {
if ($('#PlacementInfo_status_0').is(":checked")) {
$('#placed').show();
}
else {
$('#placed').hide();
}
$(document).on('click', 'input:radio[name*="PlacementInfo[status]"]', function () {
if ($(this).attr('id') == 'PlacementInfo_status_0') {
$('#placed').show();
} else {
$('#placed').hide();
}
});
});
Upvotes: 1