I have some php/html that creates a dynamic table with a set of links. When the link is clicked it loads a page $url1 and called a function called 'update' which makes a mysql call.
I am removing the table and modifying the mysql to return a single row. I want the code to 1)load the linked page ($url1) 2)run the update function that is called by onclick.
Original Table
<tr>
<td><?php echo $i; ?></td>
<td><a href="<?php echo $url1; ?>" target="_blank" class="url" onclick="update('<?php echo $row['node']; ?>');"/>Run</td>
<td><?php echo $row['level1_text']." - ".$row['level2_text']." - ".$row['level3_text']." - ".$row['level4_text'] ?></td>
<td><?php echo $row['last_run_date']; ?><input type="text" class="node" value="<?php echo $row['node']; ?>" hidden></td>
<td id="cnt"><?php echo $row['run_count']; //$idate=explode(" ",$row['insertdate']); $bdate=explode("-",$idate[0]); echo $bdate[2]."-".$bdate[1]."-".$bdate[0]; ?></td>
</tr>
I started with the 'update' function, i figured I could reduce the sql statement to return only 1 row and call the update function with this code.
<script type="text/javascript">update('<?php echo $row['node']; ?>');</script>
That doesn't seem to work so I further simplified the code for testing but my update function is not being called.
<script type="text/javascript">update('525');</script>
Any pointers? Is there a good way call this function on page load and then load the page at $url?
Related
i have three buttons (view,update,delete) , the view button is an href that goes to another page and brings an id with it, while my update triggers a modal. my problem is that when i click the view button it goes to the other page but it also triggers the update modal.
home.php
<?php
foreach($schedRow as $row)
{
?>
<tr>
<td><?php echo $row['subject_db']; ?></td>
<td><?php echo $row['section_db']; ?></td>
<td><?php echo $row['sched_day']; ?></td>
<td><?php $stime=$row['start_time'];
$etime=$row['end_time']; echo "".date('h:i a',strtotime($stime))." ~ ".date('h:i a',strtotime($etime))."";?></td>
<td>
View
<a href="#" class="btn btn-warning" data-toggle="modal"
data-target="#updateModal-<?php echo $row['sched_id']; ?>">Update</a>
Delete
<?php include'modal_update_sched.php'; ?>
</td>
</tr>
<?php
}
?>
heres the id of my modal
id="updateModal-<?php echo $row['sched_id']; ?>"
i solved it, the problem is that i called the modal in my view.php thats why it keeps triggering, note that i separated the code for my modal in another php file named modal_update_sched.php , i somewhat had an include 'modal_update_sched.php'; in my view.php, deleting it solved my problem.
I have a while loop in php like this:
<?php
while($row=mysql_fetch_array($query)){
?>
<tr>
<td><?php echo $row['user_id']?></td>
<td><?php echo $row['username']?></td>
<td><?php echo $row['reg_phone']?></td>
<td><?php echo $row['provider_id']?></td>
<td><?php echo $row['trans_id'] ?></td>
<td><input type='button' class='<?php echo $row['trans_id']?>' id="yes" value ='Yes' ></td>
</tr>
<?php
}
?>
and here is javascript code:
<script>
$('#yes').click(function() {
var trans_id=$(this).attr("class");
$.ajax({
url: 'infomation/gc_details_2.php',
data: {'id':trans_id},
success: function(result) {
$('#result').html(result);
}
});
});
</script>
When I click on button Yes, it request to gc_details_2 and result is showing trans_id of row I clicked. But it does not show like that. It showing trans_id of first row. And when I click on button of other row it does not work, and does not showing anything. Am I doing something wrong? Help me
In HTML, an id is a unique identifier. That means you can only use it once on a page.
Because only one can exist, when you're attaching the click handler, the this portion of the click handler is referencing the first element found with the unique identifier.
Change the id to a class if you want to use it multiple times on the same page.
<td><input type='button' class='yes <?php echo $row['trans_id']?>' value ='Yes' ></td>
and
$('.yes').click(function() {...}
I currently have a page that loads slow and would like to make the user experience more enjoyable. I would like to load each div so when a div is read() fade in using jQuery. Currently my code works but it loads everything at the same time and fades in. I would like it to load in order of div placement. Below is an example code of loading 2 divs with large tables in them. I would like each table to show up as soon as it's ready. The first one should be ready before the second one and it should render first. I have tried to separate the js so that each has their own ready() but that didn't work.
Also: I am more looking for a consent on how to do this rather than the specific code. What if I have a lot of divs with a lot of different tables. Not every div will have a table in it. some might have pictures or just text. There should be a way to load each div whenever it's ready to be displayed.
<!DOCTYPE html>
<html lang="en">
<head>
<link href="style/jquery-ui.css" rel="stylesheet" type="text/css"/>
<link href="style/main.css" rel="stylesheet" type="text/css" />
<link href="//cdn.datatables.net/1.10.7/css/jquery.dataTables.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="//cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"></script>
<title>Animated jQuery Fade | Script tutorial</title>
</head>
<script>
$(document).ready(function(){
$('.myTable').DataTable();
});
$(document).ready(function(){$(".content").hide().fadeIn(1000);});
</script>
<body>
<div id="header">
<h1>Welcome to test page</h1>
</div>
<div class="content" style="display: none;">
<table class="myTable">
<thead>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
</tr>
</thead>
<tbody>
<?php for($i =0; $i <10000; $i++){ ?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo $i; ?></td>
<td><?php echo $i; ?></td>
<td><?php echo $i; ?></td>
<td><?php echo $i; ?></td>
<td><?php echo $i; ?></td>
<td><?php echo $i; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<div class="content" style="display: none;">
<table class="myTable">
<thead>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
</tr>
</thead>
<tbody>
<?php for($i =0; $i <20000; $i++){ ?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo $i; ?></td>
<td><?php echo $i; ?></td>
<td><?php echo $i; ?></td>
<td><?php echo $i; ?></td>
<td><?php echo $i; ?></td>
<td><?php echo $i; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</body>
</html>
I think what you need here is to provide you DataTables with an AJAX source, which will retrieve your data. Then set a callback that will fire when the data has been loaded to fadeIn your tables.
It might look something like this:
$(document).ready(function() {
$('#myTable1').dataTable( {
"ajax"{
"url": 'path/to/datasource.php',
"success" : function(){
$('#myTable1').parent().fadeIn(1000);
}
}
} );
} );
This is untested code and the syntax may be wrong, but it should give you an idea of how this is done. Also, the returned data from your php datasource must return json in the correct format DataTables is expecting (this is very important, and is often where people make mistakes).
Please see the DataTables ajax docs here.
the problem is not about what type of data it need to display, but rather you should limit amount of data display each time, and separate the server side, from client side, so it will reduce load on browser, the code below is untested, prob lot of syntax error #_#
PHP
<?php
// you can manual hard code the data, or use database, it really didn't matter what the data are it can be path of image, text, etc...
var $textData = array(); // eg ('text1','text2')
var $imgData = array(); // eg ('path/img.jpg', 'path/img.jpg')
var $divData = array(); // eg ('<div class="parent"><div class="child"></div></div>')
// see what data set you want to get
if($_POST['type']==='text') {
// now encode the data into json for ajax
echo json_encode($textData);
} else if($_POST['type']==='img') {
echo json_encode($imgData);
}
?>
JQUERY AJAX
<script>
if(some condition are made) {
$.ajax({
url: "text.php",
type: "POST",
data: {
type: 'text' // it can be anything
},
dataType: "JSON",
success: function (dataSet) {
// jquery to append dataSet, use if() to append to different place depend on type
// this set you can hide as default with css
// after data loaded fade in with jquery.
}
});
}
</script>
Hi guys I have a table created by php in this way:
foreach ($query as $row): ?>
<tr id="<?php echo $row->aic;?>" >
<td><?php echo $row->aic; ?></td>
<td><?php echo $row->denominazione ?></td>
<td><?php echo $row->quantita; ?></td>
<td><?php echo $row->alert; ?></td>
<td>
<a id="bt_modifica"
class="btn btn-default btn-xs"
data-toggle="tooltip"
data-placement="top"
title=""
data-original-title="Modifica">
<img src="<?php echo base_url(); ?>template/images/Modifica.png">
</a>
<a id="bt_elimina>"
class="btn btn-default btn-xs"
data-toggle="tooltip"
data-placement="top"
title=""
data-original-title="Elimina"
onclick="deleteRow(<?php echo $row->aic ?>))">
<img src="<?php echo base_url(); ?>template/images/Elimina.png">
</a>
</td>
</tr>
<?php
endforeach; ?>
</tbody>
I need to delete row by rowId. This table has the dynamics id.
The columns ids are the same id of the sql table; in effect aic is id of sql table! In this way I are sure that the HTML row id is unique.
This is script
function deleteRow(rowID)
{ var row = document.getElementById(rowID);
row.parentElement.removeChild(row);
alert(rowID);
}
}
this code don't delete row.
Change this:
onclick="deleteRow(deleteRow(<?php echo $row->aic ?>))">
to
onclick="deleteRow(<?php echo $row->aic ?>)">
Another potential issue is that this:
<?php echo $row->aic ?>
may not be a number. So, you need to quote it. That is, change:
onclick="deleteRow(<?php echo $row->aic ?>)">
to:
onclick="deleteRow(\"<?php echo $row->aic ?>\")">
2 issues -
The one that might be causing issue - Incorrect Function Name
Other one - Calling deleteRow() twice - within each other (this should not cause any issue though)
So, just change -
function eliminaProdotto(rowID)
to -
function deleteRow(rowID)
Edit:
Based on modified question -
Is $row->aic a string? If yes, then add quotes around it...
onclick="deleteRow('<?php echo $row->aic ?>')"
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); ?>" />