use span to hide and show content - php

i am new in both php and jquery. i want to use span to hide and show content in html and php. can i use jquery? if yes, what should i do? i already put the jquery script to the bottom of page. this is my code :
<!-- reply -->
<span title="fas fa-reply" name="reply" data-id="1"
</span>
<!-- if span clicked show all these data... -->
<table class="table table-borderless" style="margin-top:50px;">
<thead class="bg-secondary pb-0">
<tr>
<th colspan="3" class="pb-0">
<p class="test text-light">Creating Reply <?php echo $rowAllPost["id"]; ?>
</p></th>
<th class="pb-0 text-right">
</th>
</tr>
</thead>
<th scope="row" style="width:15rem!important;">
<img src="<?php echo $rowViewUserNow["picture"];?>" class="rounded-circle" style=height:93px;width:81px;><br>
<p class="ml-3"> Online</p>
<p class="ml-2"> <?php echo $rowViewUserNow["username"];?>
</p>
<i class="fas fa-info-circle pr-2 pt-2"></i>Active
<td colspan="3" class="text-justify">
<form action="controller/doCheckPost.php" method="post">
<textarea name="description" class="form-control"></textarea>
</td>
</tr>
<tr class="bg-secondary pb-0" >
<th colspan="3" class="pb-0">
<button title="Cancel" class="btn" type="submit" name="cancel"><i class="fas fa-times"></i></th></button>
<th class= "pb-0 text-right">
<button title="Submit" class="btn" name="submit"><i class="fas fa-check"></i></button>
</form>
</th>
</th>
</tr>
</div>
</tbody>
</table>

The best way would be to first give an id to both the span and table elements. Then you can use an event handler in jQuery like this:
$('#spanId').on('click', function() {
$('#tableId').toggle();
});
Toggle will show the element if it's hidden and hide it if it's visible.

Related

How to remain same pagination page on table after action

i have created a table (using datatables) and in the table a few actions. in the table i have a button to do a function "delete", also using datatables i get pagination.. So for example i am at page 5, and i want to delete a row when i click delete it refreshes the page and goes back to page no 1. How can i make it remain at page 5 after the action delete? Below are my table and controller function
viewStatistics.blade:
<table class="table table-hover demo-table-search table-responsive-block alt-table" id="tableWithSearch">
<thead>
<tr>
<th class="text-center" style="width:80px;">ID</th>
<th class="text-center">Date</th>
<th class="text-center">Question <br> Asked</th>
<th class="text-center">Low <br> Confidence</th>
<th class="text-center">No <br> Answer</th>
<th class="text-center">Missing <br> Intent</th>
<th class="text-center">Webhook <br> Fail</th>
<th class="text-center">Status</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
#foreach($data as $sessionID => $value)
<tr>
<td class="text-center">{{$value['identifier']}}</td>
<td class="text-center">{{date("d M", strtotime($value['dateAccess']))}}</td>
<td class="text-center">{{$value['total']}}</td> <!-- question asked -->
<td class="text-center">{{$value['low confidence']}}</td> <!-- low confidence -->
<td class="text-center">{{$value['no answer']}}</td> <!-- no answer -->
<td class="text-center">{{$value['missing intent']}}</td> <!-- missing intent -->
<td class="text-center">{{$value['webhook fail']}}</td> <!-- webhook fail -->
<td class="text-center" style="{{$value['status'] == 'Reviewed' ? 'color:green' : 'color:red'}}">
{{$value['status']}}
#if($value['status'] == 'Pending')
<input type="checkbox" name="check" class="check" value="{{$sessionID}}">
#endif
</td> <!-- status -->
<td class="text-center">
<div class="btn-group">
<button type="button" class="btn alt-btn alt-btn-black dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Manage</button>
<ul class="dropdown-menu">
<li>
View
</li>
<li>
Delete
</li>
#if($value['status'] == 'Pending')
<li>
Mark as Done
</li>
#endif
</ul>
</div>
</td> <!-- action -->
</tr>
#endforeach
</tbody>
</table>
Controller:
public function deleteStatistics($companyID, $sessionID)
{
DiraChatLog::where('company_id', $companyID)->where('sessionID', $sessionID)->delete();
return redirect(action('AltHr\Chatbot\TrackerController#viewStatistics', compact('companyID')))->with('notification',[
'status' => 'success',
'title' => 'Statistics Deleted',
'message' => 'The Statistics have been deleted.'
]);
}
There is an option named stateSave in jquery datatables. Please check the code below:
$('#example').dataTable({ stateSave: true });

Displaying value in textbox for to edit using ajax and php

editModal.php
<div id="edit-modal" class="modal fade" tabindex="-1" role="dialog" aria- labelledby="myModalLabel" aria-hidden="true" style="display: none;">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">
<i class="glyphicon glyphicon-edit"></i> Edit Profile
</h4>
</div>
<div class="modal-body">
<div id="modal-loader" style="display: none; text-align: center;">
</div>
<div id="dynamic-content">
<div class="row">
<div class="col-md-12">
<div class="table-responsive">
<table class="table table-bordered">
<tr>
<th>First Name</th>
<td id="txt_first">
<input id="result_table" type="text" class="form-control" name="Firstname" ng-model="name">
</td>
</tr>
<tr>
<th>Middle Name</th>
<td id="txt_middle" > </td>
</tr>
<tr>
<th>Last Name</th>
<td id="txt_last"></td>
</tr>
<tr>
<th>Email Add</th>
<td id="txt_emailadd"></td>
</tr>
<tr>
<th>Contact Number</th>
<td id="txt_cnumber"></td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" value="send" name="submit" class="btn btn-primary">Save Changes</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div><!-- /.modal -->
</div>
$(document).on('click', '#getUser', function(e){
e.preventDefault();
var uid = $(this).data('id'); // get id of clicked row
$('#dynamic-content').hide(); // hide dive for loader
$('#modal-loader').show(); // load ajax loader
$.ajax({
url: '../model/editUser.php',
type: 'POST',
data: 'id='+uid,
dataType: 'json'
})
.done(function(data){
console.log(data);
$('#dynamic-content').hide(); // hide dynamic div
$('#dynamic-content').show(); // show dynamic div
$('#txt_first').html(data.First_Name);
$('#txt_middle').html(data.Middle_Name);
$('#txt_last').html(data.Last_Name);
$('#txt_emailadd').html(data.Email_Add);
$('#txt_cnumber').html(data.Contact_Number);
$('#modal-loader').hide(); // hide ajax loader
})
.fail(function(){
$('.modal-body').html('<i class="glyphicon glyphicon-info-sign"></i> Something went wrong, Please try again...');
});
});
});
</script>
I wanted to display the value of the $('#txt_first').html(data.First_Name); on the input type="text" value = "php echo $firstName " But it seems that I'm doing it wrong. Is it possible for me to enclosed the table and the script in a ; segment?
It is input field so you need to do it with 'value' not 'html'. try this:
$('#txt_first').val(data.First_Name);
Created demo to display data.First_Name in input type ="text"
$('#result_table').val("test");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="table table-bordered">
<tr>
<th>First Name</th>
<td id="txt_first">
<input id="result_table" type="text" class="form-control" name="Firstname" ng-model="name">
</td>
</tr>
<tr>
<th>Middle Name</th>
<td id="txt_middle" > </td>
</tr>
<tr>
<th>Last Name</th>
<td id="txt_last"></td>
</tr>
<tr>
<th>Email Add</th>
<td id="txt_emailadd"></td>
</tr>
<tr>
<th>Contact Number</th>
<td id="txt_cnumber"></td>
</tr>
</table>

Jquery remove class not working on table rows

I posted another question for issue and it was partially solved. I have a table with a single link on each row. The link calls AJAX and outputs in another Bootstrap column. This works fine. When I click the link, the class "highlight" is applied which changes the background color of the row. When I click another link I want the previously clicked clink to have the "highlight" class removed and the new row to have the class applied.
Currently, the add class works but any other link click get the class added but the class is never removed.
<table class="table table-hover unpadded" id="mashed_tab">
<thead>
<tr>
<th class="artcl_hdr text-center" colspan="2">
<p class="big_date top_pad"><i class="fa fa-rss fa-lg concrete"></i> Articles/Keywords for
2016-07-09 - 2016-07-10</p>
</th>
<th><span class="badge bkgcol-wet-asphalt">55</span></th>
</tr>
</thead>
<tbody class="mashed_body">
<tr class="mashed_row">
<td class="bkgcol-sunflower wht-border">
<div class="date_cell">
<span class="asphalt long_date">Sat</span><span class="white day">Jul 09, 2016</span>
</div>
</td>
<td class="linked-title dark unpadded">
<div class="cell_link">
link 1
</div>
</td>
<td class="small-cell">
<i class="fa fa-arrow-right"></i>
</td></tr><tr class="mashed_row">
<td class="bkgcol-sunflower wht-border">
<div class="date_cell">
<span class="asphalt long_date">Sat</span>
<span class="white day">Jul 09, 2016</span>
</div>
</td>
<td class="linked-title dark unpadded">
<div class="cell_link">
Link 2
</div>
</td>
<td class="small-cell">
<i class="fa fa-arrow-right"></i>
</td>
</tr>
<tr class="mashed_row">
<td class="bkgcol-sunflower wht-border">
<div class="date_cell">
<span class="asphalt long_date">Sat</span>
<span class="white day">Jul 09, 2016</span>
</div>
</td>
<td class="linked-title dark unpadded">
<div class="cell_link">
Link 3
</div>
</td>
<td class="small-cell">
<i class="fa fa-arrow-right"></i>
</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
$(document).ready(function() {
attachEvents();
});
function attachEvents() {
var selClass = 'highlight';
$('#mashed_tab tr a').click(function() {
$(this).parent().parent().removeClass(selClass);
$(this).parent().parent().addClass(selClass);
});
};
</script>
Try something like this in your on click function and let me know.
$('tr a').click(function() {
$("#mashed_tab tr").find("." + selClass).removeClass(selClass);
$(this).parent().parent().addClass(selClass); });

how to give the spacing between each cell in a table and make it like a different making a table

how to give the spacing between each cell in a table and make it like a different making a table in HTML.
i want to make it like a cells becoming table by combining it all together.
code:
like shown tabs in the www.quickr.com
<table class="table" width=100% cellspacing="3px" style="border-spacing:10px; ">
<tr>
<!--<td bgcolor="#FF0000">-->
<!--<td bgcolor="#F3E9AF" height="200px" width="350px" style="padding: 74px;">-->
<td style="padding: -7px;">
<!--<td bgcolor="#99E7F7">-->
<div class="column col-md-4">
<div id="c-830" class="block">
<h4><img src="images/categories/rent_7.png" height=110 width=150 style="margin-top: -5px">
<a href="#">
<strong style="color: #343434;">Rent</strong>
</a>
</h4>
<div>
</div>
</div>
</div>
</td>
<td style="padding: -35px;">
<!--<td bgcolor="#004488">-->
<div class="column col-md-4">
<div id="c-362" class="block">
<h4><img src="images/categories/buy_6.png" height=110 width=150 style="margin-top: -3px">
<a href="#">
<strong style="color: #343434;">Buy</strong>
</a>
</h4>
<div>
</div>
</div> </div>
</td>
<td style="padding: -23px;">
<div class="column col-md-4">
<div id="c-833" class="block">
<h4><img src="images/categories/sell_tag.png" height=110 width=150 style="margin-top: -5px">
<a href="#">
<strong style="color: #343434;">Sell</strong>
</a>
</h4>
<div>
</div>
</div>
</div>
</td>
</tr>
</table>
Try to give a table name and then you could add for td/tr in css a padding or border-spacing.
Try this .. by using cellpadding="value" & cellspacing="value"
Check this: Fiddle Demo
Try this .. by using
<table cellpadding="15" cellspacing="15">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
</table>

adding a new row to existing html table using PDO and bootstrap

I have a table in my form which gets its data from a MYSQL database. I am trying to make it dynamic by allow the user to add more information, however I'm having difficulties in adding an extra row directly under the last row of the query.This is the code i have so far and my attempt at adding a new row using JQuery:
<h4>Manage Courses</h4>
<div class="container">
<div class = "container-fluid">
<div id = "table_container" style="margin-top:50px;" class="mainbox col-md-6">
<div class="row clearfix">
<div class="col-md-12">
<table class="table table-bordered table-hover" id="tab_logic">
<thead>
<tr >
<!-- <th class="text-center">
#
</th> -->
<th class="text-center">
Course Code
</th>
<th class="text-center">
Course Title
</th>
<!-- <th class="text-center">
Edit
</th>
<th class="text-center">
Delete
</th> -->
</tr>
</thead>
<?php foreach ($courses as $row) {
echo "<tr><td>";
echo $row['course_code'];
echo "</td><td>";
echo $row['course_title'];
echo "</td>";
echo "</tr>"; }
?>
<tbody>
<tr id='addr0'>
<td>
1
</td>
<td>
<input type="text" name='code' placeholder='Code' class="form-control"/>
</td>
<td>
<input type="text" name='title' placeholder='Title' class="form-control"/>
</td>
<td>
<p
data-placement="top"
title="Edit"></a>
<button class="btn btn-primary btn-xs"
data-title="Edit"
data-toggle="modal"
data-target="#edit" >
<span class="glyphicon glyphicon-pencil"></span></button></p>
</td>
<td>
<p
data-placement="top"
data-toggle="tooltip"
style="margin-left:5px"
itle="Delete">
<button class="btn btn-danger btn-xs"
data-title="Delete"
data-toggle="modal"
data-target="#delete" >
<span class="glyphicon glyphicon-trash"></span></button></p>
</td>
</tr>
<tr id='addr1'></tr>
</tbody>
</table>
</div>
</div>
<a id="add_row" class="btn btn-default pull-left">Add Row
<span class="glyphicon glyphicon-plus"></span>
</a>
<a id='delete_row' class="pull-left btn btn-default">Delete Row
<span class="glyphicon glyphicon-trash"></span>
</a>
</div>
</div>
</div>
and this is the Jquery to support the add and delete buttons:
$(document).ready(function(){
var i=1;
$("#add_row").click(function(){
$('#addr'+i).html("<td>"+ (i+1) +"</td><td><input name='code"+i+"' type='text' placeholder='Code' class='form-control input-md' /> </td><td><input name='title"+i+"' type='text' placeholder='Title' class='form-control input-md'></td>");
$('#tab_logic').append('<tr id="addr'+(i+1)+'"></tr>');
i++;
});
$("#delete_row").click(function(){
if(i>1){
$("#addr"+(i-1)).html('');
i--;
}
});
});
The code adds one row underneath the last row but them adds the second row above it for some reason.
Another issue i am encountering is the ability to replicate the glyphicons for the delete and edit for each row. I would really like these to be added for each row and for the new rows being added.
Any help would be much appreciated! :)
In the html you provided there is no "#tab_logic". You are also creating rows outside of the <tbody> and <thead> options. You also are not creating html for the glyphicons in your jQuery function.
Edit: sorry there is a tab_logic. But, you need to make sure you include the html for the glypicon. A better way to do this might be to clone an existing element and insert it.
I'm not seeing the additional row being inserted as you describe:
http://jsfiddle.net/pekv2tx0/
Also: fix your HTML, this is what is causing the problems, note the closing anchor tag with no body, inside of a p tag, and you have an empty row, so it's not inserting an extra, it's already in the html:
<p
data-placement="top"
title="Edit"></a>
<button class="btn btn-primary btn-xs"
data-title="Edit"
data-toggle="modal"
data-target="#edit" >
<span class="glyphicon glyphicon-pencil"></span></button></p>
</td>
<tr id='addr1'></tr>
inside your click function, try appending an entire row to the tbody:
$("#add_row").click(function(){
$('#tab_logic tbody').append("<tr><td>"+ (i+1) +"</td><td><input name='code"+i+"' type='text' placeholder='Code' class='form-control input-md' /> </td><td><input name='title"+i+"' type='text' placeholder='Title' class='form-control input-md'></td></tr>");
i++;
});

Categories