As the title says, I want to do something when one of the elements in my loop is clicked. This is my code:
<form method="post" action="">
<div class="table-responsive">
<table class="table table-hover table-bordered " id="defaultTable" >
<thead>
<tr>
<?php
$exchangeCol = "";
<?php foreach ($allColumns as $columnValues): ?>
<th scope="col">
<?php echo $columnValues ?>
<button type="submit" name="exchange">
<i class="fas fa-exchange-alt" style="float: right; cursor: pointer" id="exch<?php $columnValues ?>"></i>
</button>
</th>
<script>
$("#<?php echo 'exch' . $columnValues ?>").on('click', function(event) {
<?php $exchangeCol = $columnValues ?>
});
</script>
<?php endforeach; ?>
<?php echo $exchangeCol; ?>
</tr>
</thead>......
and
<?php if (isset($_POST['exchange'])){
$table->moveColumn($table->setQueryString('table') , $allColumns[1] , $allColumns[2]);
} ?>
So what I tried is using jquery to pass the value to another variable outside the loop and then use that variable but it doesn't work and I still get all of columns not the column that I click.
How can I print just the column that was clicked?
source https://stackoverflow.com/questions/67892912/do-something-when-a-specific-element-in-a-loop-is-clicked-in-php
No comments:
Post a Comment