I dynamically generated a php page with a single text element form and a table of data. Each row of the table has a barcode as the name (). As I scan each barcode in the form, I'd like to change the row color using jquery.
Php page simplified:
<form id="checkinProcess" class="mainForm" method="post" action="">
<label>Barcode:</label>
<input type="text" class="required" name="barocde" id="processBarcode"/>
<input type="submit" value="submit" class="blueBtn" />
</form>
<table class="display" id="barcodeTable">
<thead>
<tr>
<th>Barcode</th>
<th>Amount</th>
<th>Code</th>
</tr>
</thead>
<tbody>
<tr id="B12345" class="odd">
<td>B12345</td>
<td>20.3</td>
<td>External</td>
</tr>
<tr id="B23456" class="even">
<td>B23456</td>
<td>19.6</td>
<td>Internal</td>
</tr>
<tr id="B34567" class="odd">
<td>B34567</td>
<td>22.0</td>
<td>Internal</td>
</tr>
</tbody>
</table>
Table Css:
tr.odd { background-color: #F9F9F9; }
tr.even { background-color: white; }
tr.curChecked {background-color: #33CC33; }
jQuery attempt:
$('#checkinProcess').submit(function(e){
e.preventDefault();
$("tr.processBarcode").removeClass("odd" "even").addClass("curChecked");
});
How do I pass the barcode scanned in the form to my JQuery to identify which tr tag's class I want changed? Can I even do that?
Thanks
<script>tr.curChecked {background-color: #33CC33; } </script>
<form id="checkinProcess" class="mainForm" method="post" action="">
<label>Barcode:</label>
<input type="text" class="required" name="barocode" id="processBarcodes" />
<input type="submit" value="submit" class="blueBtn" id="submitBtn" />
</form>
<div class="table">
<table class="display" id="testTable">
<thead class="tableheader">
<tr><th>No</th><th>Name</th><th>Age</th><th>Salary</th></tr>
</thead>
<tbody id="testBody">
<tr id="B000506" ><td>1</td><td>Abe</td><td>28</td><td>$100K</td></tr>
<tr id="B000501" ><td>2</td><td>Jimmy</td><td>29</td><td>$90K</td></tr>
<tr id="B000506" ><td>3</td><td>Dude</td><td>18</td><td>$50K</td></tr>
<tr id="B000506" ><td>4</td><td>Boyee</td><td>28</td><td>$40K</td></tr>
</tbody>
</table>
<script>
$(document).ready(function() {
$("#submitBtn").on("click", highlight);
function highlight(evt) {
evt.preventDefault();
var scanbc = $("#processBarcodes").val();
$("#" + scanbc).addClass("curChecked");
$("#processBarcodes").val('');
$("#processBarcodes").focus();
</script>
Worked.
Related
I'm currently using Codeigniter and using Ajax to post my search result through the server and result the result and display on my responsive datatable. However the result was not added into my datatable and i even try to add it with .append but it just added below my table and the search function on datatable is not searching it and it still show "No data available in table".
Here are my View :
<div id="reporting" class="container">
<h3 class="section-title">Export Time Location Panel</h3>
<form id = "search">
<div class="form-group">
<div class="form-group">
<h5>Date/ Time</h5>
<input type="datetime-local" name="datetime" id = "datetime">
<?php echo form_error('datetime'); ?>
</div>
</div>
<button type="submit" class="btn btn-primary">Confirm</button>
</form><br/>
<table class="table table-bordered table-light" >
<thead>
<tr>
<td class="id">ID</td>
<td class="na">NA Name</td>
<td class="centre">Centre Name</td>
<td class="login">Date & Time</td>
<td class="lat">Latitude</td>
<td class="long">Longtitude</td>
<td class="accuracy">Accuracy</td>
<td class="place">Location Name</td>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<?php include('footer.php'); ?>
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function() {
var tbl = $('.table').DataTable({
responsive: true,
"order": [[0, "desc"]]
})
$( "#search" ).submit(function(event) {
event.preventDefault();
var value = $("#datetime").val();
$.ajax({
type:'POST',
url:'<?php echo base_url(); ?>location/search_record',
data:{'datetime':value},
success:function(data){
$('.table').append(data);
}
});
});
} );
</script>
Here are my Model :
public function search_record(){ //Display Record at View Page
$this->load->model('location_model');
$this->load->library('form_validation');
echo '
<tr>
<td class="id">ID</td>
<td class="na">NA Name</td>
<td class="centre">Centre Name</td>
<td class="login">Date & Time</td>
<td class="lat">Latitude</td>
<td class="long">Longtitude</td>
<td class="accuracy">Accuracy</td>
<td class="place">Location Name</td>
</tr>
';
}
You have to add data to table body by
success:function(data){ tbl.rows.add($(data)).draw(); }
Please check this link
https://jsfiddle.net/kuLcqwav/3/
https://datatables.net/examples/api/add_row.html
In form I have two table in form, for example table#1, table#2. both tables are sent only one $_POST. How to get data form e.g table#1 ? Is it possible to select in some way in $ _POST ['table # 1']?
<form id="prepForm" action="" method="POST">
<table id="1" class="table tabele-conclusions table-bordered">
<thead>
<tr>
<th>Lp.</th>
<th>desc</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td><input name="row1_desc" value=""/></td>
</tr>
</tbody>
</table>
<table id="2" class="table tabele-conclusions table-bordered">
<thead>
<tr>
<th>Lp.</th>
<th>desc</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">2</th>
<td><input name="row2_desc" value=""/></td>
</tr>
</tbody>
</table>
Simple examples:
Html
<form action="/post.php" method="POST">
<input type="text" name="testinput" value="Hello world!" />
</form>
Php:
<?php
echo $_POST["testinput"]; // Hello world!
?>
Edit: When I gave this reply, there was no sample code in the question.
I am developing a website where candidate entry has to be done and record search.
I have created a single Blade view file. In which there are different section which are called based on the if condition.
My Display.blade.php view is as below
<center>
#if($ID>0)
<table border="0" width="100%">
<tr>
<td>#include('Header')</td>
</tr>
<tr>
<td style="font-family:arial;font-size:30px;text-align:center;">Edit Registration</td>
</tr>
</table>
#endif
<!--First Call-->
#if($ID < 0)
<table border="0" width="100%">
<tr>
<td>#include('Header')</td>
</tr>
<tr>
<td style="font-family:arial;font-size:30px;text-align:center;">New Registration1</td>
</tr>
</table>
<form action="/Register" method="post" target="_self">
<input type = "hidden" name = "_token" value = "<?php echo csrf_token() ?>">
<table border="1" width="70%" cellpadding="3" style="border-collapse: collapse" bordercolor="#eeeeee">
<tr>
<td>First Name</br><input type="text" name="fname" /></td>
<td>Middle Name</br><input type="text" name="mname" /></td>
<td>Last Name</br><input type="text" name="lname" /></td>
<td>Contact No</br><input type="text" name="contactno" /></td>
</tr>
<tr>
<td colspan="4" align="center"><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
#endif
</center>
Header.blade.php is as below.
<style>
.container
{
background-image: url("header.jpg");
background-repeat: repeat-all;
left:0;
top:0;
width:100%;
height:80px;
}
</style>
<div class="container">
<div class="Cname">Cube Placement</div>
<div class="rTable">
<div class="rTableRow">
<div class="rTableHead">
<strong>
<a href='{!!url('/Register'); !!}'>Register</a>
</strong></div>
<div class="rTableHead"><strong>Report</strong></div>
</div>
</div>
</div>
the code execute fine. When Edit Registration section is executed CSS is missing from the page but when New Registration section is called CSS works fine.
except that everything is working correctly.
What is wrong in my code.
To make your css accessible on every page, place the css file in a folder in the public folder and use this code in the link tag where you call the css file, preferably in the file you load on every page.
{{ URL::to('/') }}/path/style.css
Here you say to the browser go to yourdomain.com/path/style.css
Hope it works for you
This is my code, I'm trying to get data inside #download div and submit it to other file test2.php
Don't worry it is just table inside #download
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<form action="test2.php" method="post">
<textarea style="" id="file" name="file"></textarea>
<input type="submit">
</form>
<script>
$(document).ready(function(e) {
var html=$('#download').html();
$('#file').val(html);
});
</script>
<div id="download">
<div id="content">
<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="7" id="info"></td>
</tr>
<tr>
<td colspan="7" id="info_space"></td>
</tr>
<tr>
<td valign="top" class="sirinaStupca"><!-- 1. STUPAC -->
</tr>
</table>
</div>
</div>
Other file just needs to echo it, for testing purpose, but it throws me an error: Error 404
Unable to resolve the request "test2.php". When I put normal text or css() instead of table it is working. I can't figure it out why.
if(isset($_POST["file"]))
{
echo $_POST["file"];
}
How can I sort this foreach loop with jQuery? I will sort on id but I don't now how to do that.
<form id="fileForm" action="#" enctype="multipart/form-data" method="get">
<table cellpadding="2" cellspacing="0" width="100%" class="grid">
<tr>
<th>ID:</th>
<th>Time:</th>
<th>Location:</th>
<th>From IP:</th>
<th>Title (url):</th>
<th></th>
</tr>
<tr>
<td>1</td>
<td>12:00</td>
<td>Utrecht</td>
<td>192.019.192.00</td>
<td>site</td>
</tr>
</table>
</form>
http://datatables.net/ - is a client side JQuery plugin which will allow you to sort/paginate etc the final HTML that your PHP renders.
I would tend to use a server-side solution though if you have 1000s upon 1000s of rows as the time it takes to initially render the page would be very long.
<script type="text/javascript" src="/path/to/jquery-latest.js"></script>
<script type="text/javascript" src="/path/to/jquery.tablesorter.js"></script>
<table id="myTable" class="tablesorter">
<thead>
<tr>
<th>Last Name</th>
<th>First Name</th>
<th>Email</th>
<th>Due</th>
<th>Web Site</th>
</tr>
</thead>
<tbody>
<tr>
<td>Smith</td>
<td>John</td>
<td>jsmith#gmail.com</td>
<td>$50.00</td>
<td>http://www.jsmith.com</td>
</tr>
<tr>
<td>Bach</td>
<td>Frank</td>
<td>fbach#yahoo.com</td>
<td>$50.00</td>
<td>http://www.frank.com</td>
</tr>
</tbody>
</table>
<script>
$(document).ready(function()
{
$("#myTable").tablesorter( {sortList: [[0,0], [1,0]]} );
});
</script>
You can also find more info abbout this plugin on jQuery TableShorter
here is another simple sort table using php code:
make a your-file.php, insert the below code, and upload to your folder. (this example is a very simple table for sorting and processing simple values, using this sortable.js script )
<html><head>
<script src="sorttable.js"></script>
<style>
tbody tr td {color:green;border-right:1px solid;width:200px;}
</style>
</head><body>
<?php
$First = array('a', 'b', 'c', 'd');
$Second = array('1', '2', '3', '4');
if (!empty($_POST['myFirstvalues']))
{ $First = explode("\r\n",$_POST['myFirstvalues']); $Second = explode("\r\n",$_POST['mySecondvalues']);}
?>
</br>Hi User. PUT your values</br></br>
<form action="" method="POST">
projectX</br>
<textarea cols="20" rows="20" name="myFirstvalues" style="width:200px;background:url(untitled.PNG);position:relative;top:19px;Float:left;">
<?php foreach($First as $vv) {echo $vv."\r\n";}?>
</textarea>
The due amount</br>
<textarea cols="20" rows="20" name="mySecondvalues" style="width:200px;background:url(untitled.PNG);Float:left;">
<?php foreach($Second as $vv) {echo $vv."\r\n";}?>
</textarea>
<input type="submit">
</form>
<table class="sortable" style="padding:100px 0 0 300px;">
<thead style="background-color:#999999; color:red; font-weight: bold; cursor: default; position:relative;">
<tr><th>ProjectX</th><th>Due amount</th></tr>
</thead>
<tbody>
<?php
foreach($First as $indx => $value) {
echo '<tr><td>'.$First[$indx].'</td><td>'.$Second[$indx].'</td></tr>';
}
?>
</tbody>
<tfoot><tr><td>TOTAL = <b>111111111</b></td><td>Still to spend = <b>5555555</b></td></tr></tfoot></br></br>
</table>
</body>
</html>
I really like this simple solution from Nick G at jQuery table sort
$('th').click(function(){
var table = $(this).parents('table').eq(0)
var rows = table.find('tr:gt(0)').toArray().sort(comparer($(this).index()))
this.asc = !this.asc
if (!this.asc){rows = rows.reverse()}
for (var i = 0; i < rows.length; i++){table.append(rows[i])}
})
function comparer(index) {
return function(a, b) {
var valA = getCellValue(a, index), valB = getCellValue(b, index)
return $.isNumeric(valA) && $.isNumeric(valB) ? valA - valB : valA.localeCompare(valB)
}
}
function getCellValue(row, index){ return $(row).children('td').eq(index).html() }