i have a script which works for deletion confirmation...
$('document').ready(function(){
$('.ask').jConfirmAction();
});
and the table of products listing is under below
<?php if(isset($query)){ ?>
<input disabled type="hidden" id="recNum" value="<?php echo $rec ?>"/>
<table id="rounded-corner" summary="2007 Major IT Companies' Profit" width="100%">
<thead>
<tr>
<th scope="col" class="rounded-company"></th>
<th scope="col" class="rounded">Product ID</th>
<th scope="col" class="rounded">Product Name</th>
<th scope="col" class="rounded">Product slug</th>
<th scope="col" class="rounded">Type</th>
<th scope="col" class="rounded">Product Category</th>
<th scope="col" class="rounded">Edit</th>
<th scope="col" class="rounded-q4">Delete</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="7" class="rounded-foot-left"><em>All The Pages That Being Included</em></td>
<td class="rounded-foot-right"> </td>
</tr>
</tfoot>
<tbody>
<?php
foreach($query as $key => $row) {
?>
<tr>
<td><input type="checkbox" name="" /></td>
<td><?php echo $row['product_id'];?></td>
<td><?php echo $row['product_name'];?></td>
<td><?php echo $row['product_slug'];?></td>
<td><?php echo $row['type'];?></td>
<td><img src="<?php echo base_url().$row['product_image'];?>" width="80px" height="80px"/></td>
<td><img src="<?php echo base_url();?>assets/admin_assets/images/user_edit.png" alt="" title="" border="0" /></td>
<td><img src="<?php echo base_url();?>assets/admin_assets/images/trash.png" alt="" title="" border="0" /></td>
</tr>
<?php
}?>
</tbody>
</table>
<span class="bt_green_lft"></span><strong>Add new item</strong><span class="bt_green_r"></span>
<span class="bt_blue_lft"></span><strong>View all items from category</strong><span class="bt_blue_r"></span>
<span class="bt_red_lft"></span><strong>Delete items</strong><span class="bt_red_r"></span>
heres the jquery for the jQuery confirmation:
/*
* jQuery Plugin : jConfirmAction
*
* by Hidayat Sagita
* http://www.webstuffshare.com
* Licensed Under GPL version 2 license.
*
*/
(function($){
jQuery.fn.jConfirmAction = function (options) {
// Some jConfirmAction options (limited to customize language) :
// question : a text for your question.
// yesAnswer : a text for Yes answer.
// cancelAnswer : a text for Cancel/No answer.
var theOptions = jQuery.extend ({
question: "Are You Sure ?",
yesAnswer: "Yes",
cancelAnswer: "Cancel"
}, options);
return this.each (function () {
$(this).bind('click', function(e) {
e.preventDefault();
thisHref = $(this).attr('href');
if($(this).next('.question').length <= 0)
$(this).after('<div class="question">'+theOptions.question+'<br/> <span class="yes">'+theOptions.yesAnswer+'</span><span class="cancel">'+theOptions.cancelAnswer+'</span></div>');
$(this).next('.question').animate({opacity: 1}, 300);
$('.yes').bind('click', function(){
window.location = thisHref;
});
$('.cancel').bind('click', function(){
$(this).parents('.question').fadeOut(300, function() {
$(this).remove();
});
});
});
});
}
})(jQuery);
all the thing was working well,
then i made ana jax pagination for the lists;
now the problem is that after this task, the jquery confirmation isnt working, i want the jquery script to be converted into simple jquery function like this
function ask()
{
}
EDIT:
i have written the function
function ask(obj)
{
alert('hii');
//var theOptions = jQuery.extend ({
var question= "Are You Sure ?";
var yesAnswer= "Yes";
var cancelAnswer= "Cancel";
//e.preventDefault();
var thisHref = $(obj).attr('href');
alert(thisHref) ;
if($(obj).next('.question').length <= 0)
$(obj).after('<div class="question">'+question+'<br/> <span class="yes">'+yesAnswer+'</span><span class="cancel">'+cancelAnswer+'</span></div>');
$(obj).next('.question').animate({opacity: 1}, 300);
$('.yes').bind('click', function(){
window.location = thisHref;
});
$('.cancel').bind('click', function(){
$(obj).parents('.question').fadeOut(300, function() {
$(obj).remove();
});
});
}
and i am calling this from
<img src="<?php echo base_url();?>assets/admin_assets/images/trash.png" alt="" title="" border="0" />
its taking the effect also;
but just after the animating effect, its getting redirected to the link, i need to make it stay, so that user can choose the option. but i cant...
MORE EDIT:
Ok i got the answer; i used the small code return false and it solved my problem
but then there's another problem
this line of code isnt working
$('.cancel').bind('click', function(){
$(obj).parents('.question').fadeOut(300, function() {
$(obj).remove();
});
});
You need to bind $('.ask').jConfirmAction(); to all the links again after you have gone to the new page.
Related
Update, seems it is also happening when i go onto the next page (fullscreen this time).
I'm hoping someone could possible help me as this has been driving me crazy. I have a table full off orders which each row has a button. This button when submitted will show an alert.
I am using data-tables (Responsive), and when the table is all on the screen, the button works as intended. However, when the screen is resized and the button goes within the + icon to expand the row. The button is not running the jquery and is submitting the page.
I have no idea how to fix this and was wondering if there is a workaround. Here is a sample of the code if it helps.
<table id="datatable-buttons" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>Order Number</th>
<th>Button</th>
</tr>
</thead>
<tbody>
<?php foreach ($orders as $order): ?>
<tr>
<th scope="row">
<?php echo $order['OrderNumber']; ?>
</th>
<td>
<form id="<?php echo $order['OrderNumber']; ?>">
<input type="submit" value="Submit">
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
At the bottom of the page:
<?php foreach ($orders as $order): ?>
<script>
$('#<?php echo $order['OrderNumber']; ?>').on('submit', function () {
alert('Form submitted!');
return false;
});
</script>
<?php endforeach; ?>
Any help would be appreciated! I have no idea why it isn't working when the table is resized.
Use a delegated event handler instead :
$('#datatable-buttons').on('submit', '#<?php echo $order['OrderNumber'];?>', function() {
alert('Form submitted!');
return false;
});
Your event handler does not work because the form not exists in dom at the time of declaration.
But all those dedicated #id based event handlers is completely unnecessary. A single (delegated) handler is sufficient :
$('#datatable-buttons').on('submit', 'form', function () {
alert('Form ' + $(this).attr('id') + ' submitted!');
return false;
});
Hey mate you could try something like this for the alert
<table id="datatable-buttons" class="table table-striped table- bordered dt-responsive nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>Order Number</th>
<th>Button</th>
</tr>
</thead>
<tbody>
<?php foreach ($orders as $order): ?>
<tr>
<th scope="row">
<?php echo $order['OrderNumber']; ?>
</th>
<td>
<button type="button" class="btnPress" id="<?php echo $order['OrderNumber']; ?>">Submit</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
Bottom
<script>
$('.btnPress').on('click', function () {
alert('Form submitted!');
alert(this.id);
});
</script>
I am looking for information on the best approach to creating a 'more details' section on a table generated by a MySQL query which is something like this:
<tr>
<th>First Name</th>
<th>Surname</td>
<th>Details</th>
</tr>
<tr>
<td>Joe</td>
<td>Blogs</td>
<td><a class="button-1" href="">More Details</td>
</tr>
<tr>
<th class="hidden_details hidden-1" colspan="3">...insert details...</th>
</tr>
Each row has a unique id e.g. button-2,3,4 etc that I can use to create a unique class for each details section and I can hide and show the details using JQuery:
$(document).ready(function() {
$('.button-1').click(function(){
var link = $(this);
$('.hidden-1').slideToggle('slow', function() {
if ($(this).is(':visible')) {
link.text('Hide Details');
} else {
link.text('More Details');
}
});
});
});
But my knowledge on JQuery is limited so the only way I could think to call the code would be to use php to create multiple versions. If anyone could point my in the direction of the best approach I would be grateful
check this code. it will help you. here id="view_1",id="show_1" 1 is your dynamic value from database .
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<th>First Name</th>
<th>Surname</td>
<th>Details</th>
</tr>
<tr>
<td>Joe</td>
<td>Blogs</td>
<td><a class="button-1" id="view_1" href="javascript:void(0)" onclick="show_details(1)">More Details</td>
</tr>
<tr>
<th class="hidden_details hidden-1" colspan="3" id="show_1">...insert details...</th>
</tr>
<tr>
<td>Joe1</td>
<td>Blogs2</td>
<td><a class="button-1" id="view_2" href="javascript:void(0)" onclick="show_details(2)">More Details</td>
</tr>
<tr>
<th class="hidden_details hidden-1" colspan="3" id="show_2">...insert details...</th>
</tr>
</table>
<script type="text/javascript">
function show_details(id) {
if ($('#show_'+id).is(':visible')) {
$('#view_'+id).text('More Details');
$('#show_'+id).hide();
} else {
$('#view_'+id).text('Hide Details');
$('#show_'+id).show();
}
}
</script>
<style type="text/css">
.hidden_details {
display: none;
}
</style>
I am using Zend Framework and have retrieved rows from database using Zend_Db. The HTML is as below. The aim is to toggle the 'Yes/No text in the Slideshow column when clicked. The ajax call works and returns the correct result. I however have not been able to select the cell and change the text.
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>ID</th>
<th>title</th>
<th>Caption</th>
<th>Image</th>
<th></th>
<th></th>
<th>Slideshow</th>
</tr>
</thead>
<tbody>
<?php
foreach($this->sections as $section){
if($section['slide']==0){ $slideText='No'; }
if($section['slide']==1){ $slideText='Yes'; }
?>
<tr>
<td>
<span class="badge"><?php echo $section['id']; ?></span>
</td>
<td>
<?php echo $section['caption']; ?>
</td>
<td>
<?php echo $section['comment']; ?>
</td>
<td>
<img src="/images/uploads/<?php echo $section['image_url']; ?>" width="180" height="100">
</td>
<td>Edit</td>
<td>Delete</td>
<td class="imgajax"><?php echo $slideText; ?></td>
</tr>
<?php }?>
</tbody>
</table>
<?php } ?>
The javascripts follows;
$(".imgajax a").click(function(event){
event.preventDefault();
var url = $(this).url();
id = url.segment(4);
$.ajax({
type: 'GET',
url:"/admin/ajax",
data:"id="+id,
success: function(data) {
console.log(data);
if(data==1){
$('.slide').text('Yes');
}
if(data==0)
{
$('.slide').text('No');
}
}
});
});
You should use
$('.slide').html('Yes');
instead of
$('.slide').text('Yes');
I added Edit button to my jQuery Datatable. When the user clicks on this button, the row becomes editable. Updated row should be saved to MySQL DB, but here comes the problem - the updated row is not saved to DB. Firebug does not show any error message. Can someone help me figure out the problem?
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$('#newspaper-b').dataTable({
"sPaginationType":"full_numbers",
"aaSorting":[[3, "asc"]],
"bJQueryUI":true
});
$(".edit_but").click(function() {
var ID=$(this).attr('id');
$("#first_"+ID).hide();
$("#last_"+ID).hide();
$("#first_input_"+ID).show();
$("#last_input_"+ID).show();
});
$(".edit_tr").change(function() {
var ID=$(this).attr('id');
var first=$("#first_input_"+ID).val();
var last=$("#last_input_"+ID).val();
var dataString = 'flightNum='+ ID +'&from='+first+'&STADate='+last;
$("#first_"+ID).html('<img src="load.gif" />'); // Loading image
if(first.length>0&& last.length>0) {
$.ajax({
type: "POST",
url: "callpage.php?page=tables/edit.php",
data: dataString,
cache: false,
success: function(html) {
$("#first_"+ID).html(first);
$("#last_"+ID).html(last);
}
});
} else
{
alert('All fields must be filled out.');
}
});
// Edit input box click action
$(".editbox").mouseup(function() {
return false
});
// Outside click action
$(document).mouseup(function() {
$(".editbox").hide();
$(".text").show();
});
$("tr").click(function(){
$(this).addClass("selected").siblings().removeClass("selected");
});
});
</script>
<table id="newspaper-b" border="0" cellspacing="2" cellpadding="2" width = "100%">
<thead>
<tr>
<th scope="col">Flt Num</th>
<th scope="col">From</th>
<th scope="col">STA Date</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<?php foreach ($result1 as $row):
$flightNum=$row['flightNum'];
$from=$row['frm'];
$STADate=$row['STADate'];
?>
<tr id="<?php echo $flightNum; ?>" class="edit_tr">
<td><?php echo $row['flightNum'];?></td>
<td class="edit_td">
<span id="first_<?php echo $flightNum; ?>" class="text">
<?php echo $from;?>
</span>
<input type="text" value="<?php echo $from;?>"
class="editbox" id="first_input_<?php echo $flightNum; ?>"/>
</td>
<td class="edit_td">
<span id="last_<?php echo $flightNum; ?>" class="text">
<?php echo $STADate; ?>
</span>
<input type="text" value="<?php echo $STADate; ?>"
class="editbox" id="last_input_<?php echo $flightNum; ?>"/>
</td>
<td class="edit_td"><?php echo $row['pkID']; ?></td>
<td id="<?php echo $flightNum; ?>" class="edit_but">
<div>
<img src='images/edit.png' alt='Edit' />
</div>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
edit.php
<?php
include_once 'include/DatabaseConnector.php';
if(isset($_POST['flightNum'])) {
$flightnum=$_POST['flightNum'];
$from=$_POST['from'];
$STADate=$_POST['STADate'];
$query = 'UPDATE flightschedule
SET frm="'.$from.'",STADate="'.$STADate.'"
WHERE flightNum="'.$flightNum.'"';
DatabaseConnector::ExecuteQuery($query);
echo '1';
} else {
echo '0';
}
?>
Try $(".edit_tr input").change() as the trigger.
Change events are limited to inputs, selects and textareas only, but you've tried binding it to a table row. The code above will bind it to any inputs inside the row with the class.
Anyone have any idea why my page numbers are not listing inside of the pagination div? I'm using the tablesorter.pager plugin.
<?php
session_start();
require("../inc/dbconfig.php");
require("../inc/global_functions.php");
// find out how many rows are in the table
$query = "SELECT CONCAT_WS(' ',firstName,lastName) AS name, username, emailAddress, userID FROM manager_users WHERE statusID != 4";
$result = mysqli_query($dbc,$query);
$fileName = basename($_SERVER['PHP_SELF']);
$pageName = "User Accounts";
$userData = $_SESSION['user_data'];
$userID = $userData['userID'];
?>
<script type="text/javascript">
$(document).ready(function() {
$('a.bt_green').click(function(e) {
e.preventDefault();
$('div.right_content').load('forms/addnew/' + $(this).attr('id'));
});
$('#usersPageList').tablesorter().tablesorterPager({container:$('#pagination'),cssPageLinks:'a.pageLink', positionFixed: false});
$('table tr').click(function() {
checkBox = $(this).children('td').children('input[type=checkbox]');
if(checkBox.attr('checked'))
checkBox.removeAttr('checked');
else
checkBox.attr('checked', 'checked');
});
$('.ask').jConfirmAction();
$('.ask2').jConfirmAction();
});
</script>
<h2>User Accounts</h2>
<table id="usersPageList" class="rounded-corner">
<thead>
<tr>
<th scope="col" class="rounded-first"></th>
<th scope="col" class="rounded">Name</th>
<th scope="col" class="rounded">Email Address</th>
<th scope="col" class="rounded">Username</th>
<th scope="col" class="rounded">Edit</th>
<th scope="col" class="rounded-last">Delete</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="5" class="rounded-foot-left"><em>Displays all of the registered and verified users!</em></td>
<td class="rounded-foot-right"> </td>
</tr>
</tfoot>
<tbody>
<?php
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
echo "<tr>";
echo "<td><input type=\"checkbox\" name=\"users[]\" value=\"".$row['userID']."\"/></td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['emailAddress']."</td>";
echo "<td>".$row['username']."</td>";
echo "<td><img src=\"images/user_edit.png\" alt=\"\" title=\"\" border=\"0\" /></td>";
echo "<td>";
if (($row['userID'] !== '10000') && ($row['userID'] !== $userID)){
echo "<img src=\"images/trash.png\" class=\"delete\" alt=\"\" title=\"\" border=\"0\" id=\"".$row['userID']."\" />";
}
echo "</td>";
echo "</tr>";
}
?>
</tbody>
</table>
<div id="pagination"></div>
<?php
addRemove($fileName,$pageName);
?>
<input type="hidden" name="myhiddenPageToken" id="myhiddenPageToken" value="useraccounts" />
EDIT POST:
<script type="text/javascript">
$(document).ready(function() {
$('a.bt_green').click(function(e) {
e.preventDefault();
$('div.right_content').load('forms/addnew/' + $(this).attr('id'));
});
$('#usersPageList').tablesorter().tablesorterPager({container:$('#pagination'),cssPageLinks:'a.pageLink', positionFixed: false});
$('table tr').click(function() {
checkBox = $(this).children('td').children('input[type=checkbox]');
if(checkBox.attr('checked'))
checkBox.removeAttr('checked');
else
checkBox.attr('checked', 'checked');
});
$('.ask').jConfirmAction();
$('.ask2').jConfirmAction();
});
</script>
<h2>User Accounts</h2>
<table id="usersPageList" class="rounded-corner">
<thead>
<tr>
<th scope="col" class="rounded-first"></th>
<th scope="col" class="rounded">Name</th>
<th scope="col" class="rounded">Email Address</th>
<th scope="col" class="rounded">Username</th>
<th scope="col" class="rounded">Edit</th>
<th scope="col" class="rounded-last">Delete</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="5" class="rounded-foot-left"><em>Displays all of the registered and verified users!</em></td>
<td class="rounded-foot-right"> </td>
</tr>
</tfoot>
<tbody>
<tr><td><input type="checkbox" name="users[]" value="10000"/></td><td>KOW Management</td><td>kowmanagement#kansasoutlawwrestling.com</td><td>Administrator</td><td><img src="images/user_edit.png" alt="" title="" border="0" /></td><td></td></tr><tr><td><input type="checkbox" name="users[]" value="10001"/></td><td>Jeff Davidson</td><td>xtremer360#yahoo.com</td><td>xtremer360</td><td><img src="images/user_edit.png" alt="" title="" border="0" /></td><td></td></tr>
</tbody>
</table>
<div id="pagination"></div>
<span class="bt_green_lft"></span><strong>Add New User Accounts</strong><span class="bt_green_r"></span><span class="bt_blue_lft"></span><strong>View all User Accounts</strong><span class="bt_blue_r"></span><span class="bt_red_lft"></span><strong>Delete User Accounts</strong><span class="bt_red_r"></span><input type="hidden" name="myhiddenPageToken" id="myhiddenPageToken" value="useraccounts" />
For the tablesorterPager plugin to work in your code I had to add a pagination form myself. I changed the pagination div to this, copied from the documentation:
<div id="pagination">
<form>
<img src="../addons/pager/icons/first.png" class="first"/>
<img src="../addons/pager/icons/prev.png" class="prev"/>
<input type="text" class="pagedisplay"/>
<img src="../addons/pager/icons/next.png" class="next"/>
<img src="../addons/pager/icons/last.png" class="last"/>
<select class="pagesize">
<option selected="selected" value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
<option value="40">40</option>
</select>
</form>
</div>
The tablesorterPager now works, and also fixes the tablesorter which breaks if tablesorterPager can't find the form.
I can't see any reference in jquery.tablesorter.pager.js to generate the form itself, so I guess you'll have to create it server-side based on the number of results in the table, and the number of results you'd like per page.
Hope that helps