PHP
<?php
$periods = "select * from perodicity";
$periods = $conn->query($periods) or die ($conn>error.__LINE__);
$peris = [];
while ($row = $periods->fetch_assoc()) {
$peris[] = $row;
}
//for service 1
$all_activities = "select * from activity join displayserviceactivitymap on activity.activity_id = displayserviceactivitymap.activity_id right join services on services.service_id = displayserviceactivitymap.service_id";
$all_activities = $conn->query($all_activities) or die ($conn>error.__LINE__);
$activities = [];
while ($row = $all_activities->fetch_assoc()) {
$activities[] = $row;
}
$repeated = 'repeated';
foreach ($activities as $act) {
if($act['servicename'] != $repeated){
?>
<form action="page5_form.php" method="post" name= "test">
<ul>
<li>
<input name='service' type='checkbox' data-id='Incometax'value="<?php echo $service['service_id']?>"/><?php echo $act['servicename']?>
<?php $repeated = $act['servicename'];}?>
<ol>
<li>
<?php if($act['activity_id'] != '')
echo '<input type="checkbox" name="arr['.$act['service_id'].'][activity][]" value="'.$act['activity_id'].'" id="'.$act['activity_id'].'">'.$act['nameofactivity'].'<br>';
?>
<!-- <input type='checkbox' name='activity' value="<?php echo $activity['id']?>" />Revised Return Filling<br> -->
</li>
<li>
<?php foreach ($peris as $per) : ?>
<input type='checkbox' name='periodicity' value="<?php echo $per['periodicity_id'];?>" /><?php echo $per['per_time'];?>
<?php endforeach ?>
</li>
<br>
<br>
<br>
</ol>
</li>
</ul>
<?php }?>
<input name="number" type="hidden" value="<?php echo $next; ?>">
<input type="submit" name="submit" value="Submit"/>
</form>
PHP代码输出:
此处所得税和Gst是服务,而其他是与该服务相关的活动。
我使用javascript代码显示和隐藏与服务相关的活动,但是当我单击 Incometax 时,只有一个活动 Return 显示,与GST相同 当我点击 GST 时,只会显示一个修订版。
我想显示与该服务相关的所有活动,单击该服务即可。
我的Javascript代码
let _flags={
capture:false,
once:false,
passive:true
};
document.addEventListener( 'DOMContentLoaded',function( evt ){
let _form = document.forms.test;
let _class= 'visible';
Array.prototype.slice.call( _form.querySelectorAll( 'input[ type="checkbox" ]' ) ).forEach( function( el, i ){
if( el.dataset.id ) el.addEventListener( 'click', function( e ){
/* Hide all `OL` elements & uncheck */
Array.prototype.slice.call( _form.querySelectorAll( 'li ol' ) ).forEach( function( n ){
if( n.classList.contains( _class ) ) {
/* Remove the class from child OL element that contains other input elements ( activities ) */
n.classList.remove( _class );
/* Uncheck the other service checkbox */
n.parentNode.querySelector( 'input[ type="checkbox" ]' ).checked=true;
/* uncheck all child activity checkboxes */
Array.prototype.slice.call( n.querySelectorAll( 'input[ type="checkbox" ]' ) ).forEach( function(chk){
chk.checked ;
} );
}
} );
/* Display relevant activity checkboxes */
if( e.target.checked ) e.target.parentNode.querySelector( 'ol' ).classList.toggle( _class )
}, _flags );
});
}, _flags );
谢谢