In Foreach loop of php i get on click event only 'product_title' and 'email'. code is as bellow.
foreach($abs_records as $abs)
{
<tr>
<td><input type="checkbox" name="case[]" class="case" ></td>
<td><?php echo $abs['product_id']; ?></td>
<td><?php echo $abs['product_title']; ?></td>
<td><?php echo $abs['user_email']; ?></td>
<td class="send_mail_btn"><a href="javascript:void(0)" >Send</a></td>
</tr><?php
} ?>
Using Jquery click on 'Send' i will get the result of Single Time value of 'Product_title' and 'user_email'
Can you suggest me.
Thanks.
Add a class to the td element like so:
<tr>
<td><input type="checkbox" name="case[]" class="case" ></td>
<td><?php echo $abs['product_id']; ?></td>
<td class="title"><?php echo $abs['product_title']; ?></td>
<td class="email"><?php echo $abs['user_email']; ?></td>
<td class="send_mail_btn"><a href="javascript:void(0)" >Send</a></td>
</tr>
Than you can find the related values in jQuery:
$(document).on('click', '.send_mail_btn', function() {
var title = $(this).siblings('.title').html();
var email = $(this).siblings('.email').html();
console.log("Title: " + title);
console.log("Email: " + email);
});
add class to email and title td and also add class to send anchor tag + add click event in jquery to get value
foreach($abs_records as $abs)
{
<tr>
<td><input type="checkbox" name="case[]" class="case" ></td>
<td><?php echo $abs['product_id']; ?></td>
<td class="title"><?php echo $abs['product_title']; ?></td>
<td class="email"><?php echo $abs['user_email']; ?></td>
<td class="send_mail_btn"><a class="send-link" href="javascript:void(0)" >Send</a></td>
</tr><?php
} ?>
Jquery:
$(".send-link").click(function() {
var title = $(this).parent("tr").find(".title").text();
var email = $(this).parent("tr").find(".email").text();
alert(title+ " -- "+email)
});
Related
I have a Chart with an select option for the Year, by the default the selection option will choose the newest Year, but the user can choose to see another data from another Year through this select option
<script type="text/javascript">
$(document).ready(function() {
$('table.highchart').highchartTable();
$('.btnTahun').click(function() {
$coba = $('#Year').val();
$.ajax({
type: 'POST',
url: "<?php echo site_url('dashboard/list_data/')?>",
data: {'tahun':$coba},
success: function(data) {
$("#tableChart").html(data);
}
});
});
});
</script>
The problem is when I choose another Year the previously selected year still exist in my view, i want to make it that only the selected year will be show in my view, take a look at my picture below, as u can see i choose year 2016, but the data chart from 2017 is still showed in my view, and i don't want that, what is wrong with my Ajax? or Perhaps is it possible because my controller or Model?
Structure of My Html to show the chart can be seen below
<table id="tableChart" class="highchart" data-graph-container-before="1" data-graph-type="column">
<thead style="display: none">
<tr>
<th>Month</th>
<th>Category Project</th>
</tr>
</thead>
<tbody style="display: none">
<tr>
<td>Jan</td>
<td><?php echo $januari ?></td>
</tr>
<tr>
<td>Feb</td>
<td><?php echo $februari ?></td>
</tr>
<tr>
<td>Mar</td>
<td><?php echo $maret ?></td>
</tr>
<tr>
<td>Apr</td>
<td><?php echo $april ?></td>
</tr>
<tr>
<td>May</td>
<td><?php echo $mei ?></td>
</tr>
<tr>
<td>June</td>
<td><?php echo $juni ?></td>
</tr>
<tr>
<td>July</td>
<td><?php echo $juli ?></td>
</tr>
<tr>
<td>Aug</td>
<td><?php echo $agustus ?></td>
</tr>
<tr>
<td>Sep</td>
<td><?php echo $september ?></td>
</tr>
<tr>
<td>Oct</td>
<td><?php echo $oktober ?></td>
</tr>
<tr>
<td>Nov</td>
<td><?php echo $november ?></td>
</tr>
<tr>
<td>Dec</td>
<td><?php echo $desember ?></td>
</tr>
</tbody>
You can use form submit rather than ajax since your controller function creates another view when you call it. heres a link for form helper https://www.codeigniter.com/userguide3/helpers/form_helper.html
CONTROLLER
public function list_data(){
$this->load->helper('form');
$thn = $this->input->post('tahun');
$data['januari'] = $this->dashboard_m->get_kategori_totals('01',$thn)->num_rows();
$data['februari'] = $this->dashboard_m->get_kategori_totals('02',$thn)->num_rows();
$data['maret'] = $this->dashboard_m->get_kategori_totals('03',$thn)->num_rows();
//And the code above will be the same until december, the differences only in the parameter
$data['title'] = 'Aplikasi Saranabudi';
$data['aktif'] = 'Jumlah Kategori Project';
$data['judul_hal']= 'Dashboard Kategori Project';
$this->load->view('dashboard/kategori_project/list_data',$data);
}
VIEW
$attributes = array('id' => 'myID', 'name' => 'myName', 'class' => 'myClass', 'method' => 'post');
echo form_open('', $attributes);
$options = array(
'2015' => '2015',
'2016' => '2016',
'2017' => '2017',
'2018' => '2018',
);
echo form_dropdown('tahun', $options);
// THE CHART
echo form_submit(array('id' => 'filter_button', 'name' => 'filter_button'), 'Filter');
echo form_close();
AS title, I want to create array in document.getElementById because my id is come from repeat region. Below is my javascript and html.
<script type ="text/javascript">
$(document).ready(function(){
$('table tbody tr').click(function(){
var PurchaserID = window.opener.document.getElementById("PurchaserID");
var n = 5;
PurchaserID.value = document.getElementById("test[n]").innerText;
alert(PurchaserID.value);
window.close();
});
});
</script>
<?php do { ?>
<tr>
<td id = "test[<?php echo $row_Purchaser['ID'];?>]" align="center" ><?php echo $row_Purchaser['ID'];?></td>
<td align="center"><?php echo $row_Purchaser['Name']; ?></td>
<td align="center"><?php echo $row_Purchaser['IC']; ?></td>
<td align="center"><?php echo $row_Purchaser['Handphone']; ?></td>
</tr>
<?php } while ($row_Purchaser = mysql_fetch_assoc($Purchaser)); ?>
Any problem of my program. Why I can't get the value test[n] to test[5] even I create var n =5; May I know how to solve it. Thanks if you could me !!
I want to get dynamic values from php in js in a dynamic manner...Let me elaborate: First I show the image then code:
<div id="">
<table border="1" width="820" style="margin-left:15px;">
<tr>
<th>Sr #</th>
<th>Commented Post</th>
<th>Commenter Name</th>
<th>Commenter Email</th>
<th>Comments</th>
<th>Status</th>
</tr>
<?php
$values = array();
while($row= mysqli_fetch_assoc($res)) {
$values[] = $row['comment_id'];
?>
<tr align="center" style="height:50px;">
<td><?php echo $row['comment_id']; ?></td>
<td><?php echo $row['post_title']; ?></td>
<td><?php echo $row['comment_name']; ?></td>
<td><?php echo $row['comment_email']; ?></td>
<td><?php echo $row['comment_text']; ?></td>
<td>
<?php
if($row['status']==0) { ?>
<div class="status_<?php echo $row['comment_id']; ?>" id="status_<?php echo $row['comment_id']; ?>">Unapproved</div>
<?php } else { ?>
Approved
<?php } ?>
</td>
</tr>
<?php }
?>
</table>
</div>
And Js here's:
<script type="text/javascript">
$(document).ready(function(){
var values = <?php echo json_encode($values); ?>;
var id = values[0];
$('.status_'+id).click(function(){
$("#status_"+id).html("<b>Test</b>");
});
var i = values[1];
$('.status_'+i).click(function(){
$("#status_"+i).html("<b>Test</b>");
});
});
</script>
I want to get all comment id's in js dynamically, so that on clicking each row link, it changes to text "Test"...As I have written the js code manually...how we obtain all the comment_id's dynamically in js..I hope you got the idea what I am trying to do...
There's no point in assigning unique ids to each of your elements. Why not do something like:
<tr>
<td>...</td>
<td><a href="#" onclick="toggle(this, <?php echo $id ?>)">Unapproved</td>
</tr>
then something like
function toggle(node, id) {
node.parentNode.innerHTML = '<b>test</b>';
... do something with "id" value? ...
}
No need for getElementById, assigning a massive pile of repetitive ids, etc.. just a single function call and a bit of DOM tree traversal.
Try to add a class to your status TD, like <td class="status" data-id="<?php echo $row['comment_id'] ?>">// your inital value</td>.
Using jQuery you can easily listen for events which are attached to a an event listener:
$(document).on('click', '.status', function() {
var id = $(this).attr('data-id');
$(this).html('<strong>Test</strong>');
// maybe to something with ajax?
$.ajax({
url: 'yourfile.php?call=doSomething&id=' + id,
type: 'post'
}).done(function(response) {
// console.log(response);
});
});
You dont appear to actually use the ids.
All you need to do is ascertain the clicked element, which use can do using this
html:
<div class="status">Unapproved</div>
js:
$(document).ready(function(){
$('.status').click(function(){
$(this).html("<b>Test</b>");
});
});
I got the following php foreach loop in the A page of my web appliation. And i want to use the $watson variable which is inside this loop in an other php B page. What i did is used this variable as a value in an extra input button:<input type="button"/ value="<?php echo $watson; ?>,so to be able to capture this var in javascript like you see below.
<tbody>
<?php
foreach($records as $r) {
$watson = $r->case_reference;
?>
<tr>
<td><?php echo escape($r->user); ?></td>
<td><?php echo escape($r->customer); ?></td>
<td><?php echo escape($r->vessel); ?></td>
<td><?php echo escape($r->country); ?></td>
<td><?php echo escape($r->port); ?></td>
<td><?php echo escape($r->eta); ?></td>
<td><?php echo escape($r->service_station); ?></td>
<td><?php echo escape($r->type_of_service); ?></td>
<td><?php echo escape($r->case_reference); ?></td>
<td><?php echo escape($r->status); ?></td>
<td><input type="button" value="<?php echo $watson; ?>" onclick="popEdit(this.value);" /></td>
</tr>
<?php
}
?>
</tbody>
The code for the onclick="popEdit(this.value);"function which pops up the B page mentioned above is :
function popEdit(str) {
window.open("example.php?watson="+str, "pop_edit_jobs",
"width=400,height=350,scrollbars=no,left=460,top=400")
}
And the php B page code starts as $ref_num = $_GET['watson']; so i can use the variable.
My problem is that i dont want the input/button in the A page to show the variable on it instead i want it to just show the word EDIT.But to do that i ll have to change its value and then i wont be able to capture this $watson var in javascript.
Any suggestions regarding how to achieve the above effect?
<td><input type="button" value="EDIT" onclick="popEdit('<?php echo $watson; ?>');" /></td>
should achieve the desired effect.
Wrap a form around your entire table, then use submit buttons:
<input type="submit" name="watson" value="<?php echo htmlspecialchars($watson); ?>" />
I'm trying to use the popover element from bootstrap's framework for Javascript/jQuery and it only works with the first one in the while loop. How can I make it work for all of them?
Why is this? Been trying to figure this out for a bit...
<?php
require 'include.php';
session_start();
$selectBets = $dbc->query("SELECT * FROM `bets` ORDER BY `bid` DESC LIMIT 10");
?>
<style type="text/css">
#hash_text {
font-size: 3.8px;
}
</style>
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Bet Number</th>
<th>Amount</th>
<th>Send Address</th>
<th>Time Created</th>
<th>Time Expires</th>
<th>Chance to Win</th>
<th>Payout Multiplier</th>
<th>Final Profit</th>
<th>Server Hash</th>
</tr>
</thead>
<tbody>
<?php while($BetsArray = $selectBets->fetch()) { ?>
<tr>
<td><?php echo $BetsArray['bid']; ?></td>
<td><?php echo $BetsArray['amount']; ?></td>
<td><?php echo $BetsArray['deposit_address']; ?></td>
<td><?php echo date('m/d/Y - H:i:s', $BetsArray['time_created']); ?></td>
<td><?php echo date('m/d/Y - H:i:s', $BetsArray['time_expires']); ?></td>
<td><?php echo $BetsArray['win_chance']; ?></td>
<td><?php echo $BetsArray['multiplier']; ?></td>
<td><?php echo $BetsArray['profit']; ?></td>
<td><a id="hash" data-container="body" data-toggle="popover" data-placement="right">Click here for Server Hash</a></td>
</tr>
<?php } ?>
</tbody>
</table>
<script type="text/javascript">
$(function() {
$('#hash').popover({
html: true,
placement: 'right',
content: '<?php echo '<span id="hash_text">' . hash('sha512', $BetsArray['number'] . '-' . $_SESSION['client_seed']) . '</span>'; ?>'
});
});
</script>
You are creating the popover element by duplicating the ids. Change it to class and see it working.
<a id="hash" data-container="body" data-toggle="popover" data-placement="right">Click here for Server Hash</a>
When you bind to the popover using the id selector $('#hash') it will select only the first element with id that appears in DOM and hence the behavior that you are seeing.
If you want to place a quick fix then you can use attribute selector to select the id like this.
$('[id=hash]').popover({
html: true,
placement: 'right',
content: '<?php echo '<span id="hash_text">' . hash('sha512', $BetsArray['number'] . '-' . $_SESSION['client_seed']) . '</span>'; ?>'
});
But never ever do that