Styling table generated by PHP foreach with jQuery - php

I am trying to style a <tr id="options"> generated by a PHP foreach() with jQuery, but everything I've tried only selects the first one, leaving the others intact. What can I do this? Simple example:
CSS:
td {border:1px solid black}
TABLE:
<table>
<tr>
<td>DATE</td>
<td>EXAM TITLE</td>
<td>EXAM CODE</td>
</tr>
<tr>
<td>TODAY</td>
<td>RANDOM</td>
<td>123</td>
</tr>
<tr>
<td>BUTTON</td>
<td>BUTTON</td>
<td>BUTTON</td>
</tr>
<tr>
<td colspan=3 id="options">
</tr>
I have tried this jQuery code (among other):
$("table").find("#options").each(function(){
$(this).css("border","0px");
});
It only styles my first <td id="options">. How can I get all of them?
Sorry if it is a stupid question. Thanks for the help.

convert id to classlike:- <td class="options">..</td>
and then you can use(Use Either-one)
CSS (standered way):-
td.options {border:1px solid black}
Or jQuery(try to avoid as much as possible):-
$('.options').css("border","1px solid black"); // no need of each
Example (both at same time):-
$('.options').css("font-size","21px");
td.options {border:1px solid black}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td class="options">DATE</td>
<td class="options">EXAM TITLE</td>
<td class="options">EXAM CODE</td>
</tr>
<tr>
<td class="options">TODAY</td>
<td class="options">RANDOM</td>
<td class="options">123</td>
</tr>
<tr>
<td class="options">BUTTON</td>
<td class="options">BUTTON</td>
<td class="options">BUTTON</td>
</tr>
</table>

Related

How to post many data from a view to controller?

I am using codeigniter.I have a table in my view. When one row is filled totally that data must be posted to my controller class. How to do this.
My view page.
<table style=" border-collapse: collapse;">
<tr>
<th>Employee</th>
<th>Start Time</th>
<th>ID</th>
<th>Mins</th>
<th>Type</th>
</tr>
<tr id="1">
<td contenteditable="true"><?php echo form_dropdown('employee', $options_category, set_value('employee'),'style="border-radius:0px; height:15px; font-size:10px; width:70px"');?></td>
<td contenteditable="true"><?php echo $date->format( 'H:i' ); ?></td>
<td contenteditable="true" ondblclick="mylist()"><?=$products['id']?></td>
<td contenteditable="true" class="nr"><?=$products['mins']?></td>
<td contenteditable="true"><?=$products['type']?></td>
</tr>
<tr id="2">
<td contenteditable="true"><?php echo form_dropdown('employee', $options_category, set_value('employee'),'style="border-radius:0px; height:15px; font-size:10px; width:70px"');?></td>
<td contenteditable="true"></td>
<td contenteditable="true" ondblclick="mylist()"><?=$products['id']?></td>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
</tr>
</table>
I need to post the id that is filled totally.How to do this can someone help me code?

Getting value of specific td in selected row

I have the way to get the value of the td's at the time the row is selected using
$(this).find('.servid').val()
However I cannot find the way to get this value later.
<table id="servicetable" class="scroll" style="border: 1px solid #cbcbcb;" align="center">
<tbody>
<tr class="selected">
<td>Service</td>
<td class="servid" value="4004072">72569000</td>
<td class="origin">PAC</td>
<td class="street">60 KENDAL</td>
<td class="city">SANRDINO</td>
<td class="state">CA</td>
<td class="zip">99999</td>
</tr>
<tr>
<td>TelePacific Circuit</td>
<td class="servid" value="5369592">77051900</td>
<td class="origin">TP</td>
<td class="street">819 KAISER</td>
<td class="city">AHEM</td>
<td class="state">CA</td>
<td class="zip">88888</td>
</tr>
</tbody>
</table>
I need to later, after filling out more of the form, get the val() of the selected tr -> servid td
I have tried various things but they are not working
$('#servicetable .selected > td:nth-child(2)').val();
$('#servicetable').find('.selected > td:nth-child(2)').val();
$('#servicetable').find('tr.selected').find('.servid').val();
Below goes your sollution
alert($('#servicetable tr.selected > td.servid').attr('value'));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table id="servicetable" class="scroll" style="border: 1px solid #cbcbcb;" align="center">
<tbody>
<tr class="selected">
<td>Service</td>
<td class="servid" value="4004072">72569000</td>
<td class="origin">PAC</td>
<td class="street">60 KENDAL</td>
<td class="city">SANRDINO</td>
<td class="state">CA</td>
<td class="zip">99999</td>
</tr>
<tr>
<td>TelePacific Circuit</td>
<td class="servid" value="5369592">77051900</td>
<td class="origin">TP</td>
<td class="street">819 KAISER</td>
<td class="city">AHEM</td>
<td class="state">CA</td>
<td class="zip">88888</td>
</tr>
</tbody>
</table>
One more thing you can not put value like this as it will not validate as per w3c, recommanded to put data-value, if HTML5.
And in jquery also you can put like
alert($('#servicetable tr.selected > td.servid').attr('data-value'));
$('#value1').text($('#servicetable .selected > td:nth-child(2)').attr('value'));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table id="servicetable" class="scroll" style="border: 1px solid #cbcbcb;" align="center">
<tbody>
<tr class="selected">
<td>Service</td>
<td class="servid" value="4004072">72569000</td>
<td class="origin">PAC</td>
<td class="street">60 KENDAL</td>
<td class="city">SANRDINO</td>
<td class="state">CA</td>
<td class="zip">99999</td>
</tr>
<tr>
<td>TelePacific Circuit</td>
<td class="servid" value="5369592">77051900</td>
<td class="origin">TP</td>
<td class="street">819 KAISER</td>
<td class="city">AHEM</td>
<td class="state">CA</td>
<td class="zip">88888</td>
</tr>
</tbody>
</table>
<label id="value1"/>
IDEAL WAY
use data attribute as shown below,
<td class="servid" data-value="4004072">72569000</td>
$('#value1').text($('#servicetable .selected > td:nth- child(2)').data('value'));
It might be better if you tag the TR with the id you need and then have the "attributes" in the TDs.
You can then parse TDs based on TR
<tr class="selected" id="98989">
<td class="city">Lisbon</td>
.....
_tr = $("#servicetable .selected");
_trId=_tr.attr("id");
_trCity = _tr.find(".city").text();
.....

How to make right border table tcpdf smaller?

I try to create tcpdf using writeHTML like this $pdf->writeHTML($html, true, 0, false, 0); which $html value like code below
<table border="1">
<tr>
<td width="100%" colspan="4">
<table border="0">
<tr>
<td width="18%" style="border-right:0.01px">Test 1</td>
<td width="12%">Test 2</td>
<td width="20%">Test 3</td>
</tr>
<tr>
<td width="18%" style="border-right:0.01px">Test 4</td>
<td width="12%">Test 5</td>
<td width="20%">Test 6</td>
</tr>
</table>
</td>
</tr>
</table>
style="border-right:0.01px" or style="border-right:0.1px" or style="border-right:1px" provide same result of border width, how to make this right border smaller? because my result rigth border on Test 1 and Test 4 are biggest then outside border.
If you're a little more explicit in your border definition it'll work as you expect. TCPDF's HTML/CSS parser is rather limited so it helps to be as specific as possible with your styling rules and the like.
Your code should work with either border-right-width: 0.1px or with the rest of CSS properties for the shorthand of border-right, see the example HTML below and accompanying screenshot of a rendered PDF (zoomed to highlight difference)
<table border="1">
<tr>
<td width="100%" colspan="4">
<table border="0">
<tr>
<!-- This should work -->
<td width="18%" style="border-right-width:0.1px;">Test 1</td>
<td width="12%">Test 2</td>
<td width="20%">Test 3</td>
</tr>
<tr>
<!-- As should this -->
<td width="18%" style="border-right:0.1px solid black;">Test 4</td>
<td width="12%">Test 5</td>
<td width="20%">Test 6</td>
</tr>
<tr>
<!-- However, this does not. -->
<td width="18%" style="border-right:0.1px">Test Broken</td>
<td width="12%">Test :)</td>
<td width="20%">Test :)</td>
</tr>
</table>
</td>
</tr>
</table>
As you can see, it handles the first two definitions as expected with thinner borders.
I use style="border-right-color:white" to hidden right border
<td style="border-right-color:white; border-bottom-color:black; border-top-color:black"></td>

Xpath nested tables

I have a Table, see Code. Its a table that has a table in it, so its nested. Now i want to get all vales of the parent table only and then all values of the child table.
To get the childs data i can do this:
$query = '//*[#id="WordClass"]/table[2]/tr/td[2]/table/tr';
$nodes = $xpath->query($query);
foreach ($nodes as $node) { //do more querys to get the td data and save it..
My problem is how to only get the data of the parent table without getting the child data/tr/td also.
<table cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr valign="top">
<td>
<table cellpadding="1" cellspacing="2" border="0">
<tr>
<td class="colTitle" align="center" colspan="4">
Da Titel
</td>
</tr>
<tr>
<td class="colTitle" align="center" colspan="2">One
</td>
<td class="colTitle" align="center" colspan="2">Two
I
</td>
</tr>
<tr>
<td class="colSubTitle">Pe</td>
<td class="colSubTitle">Ve</td>
<td class="colSubTitle">Pe</td>
<td class="colSubTitle">Ve</td>
</tr>
<tr>
<td class="rowTitle">x</td>
<td class="colVerbDef">y</td>
<td class="rowTitle">z</td>
<td class="colVerbDef">c</td>
</tr>
<tr>
<td class="rowTitle">r</td>
<td class="colVerbDef">t</td>
<td class="rowTitle">z</td>
<td class="colVerbDef">z</td>
</tr>
</table>
</td>
<td>
<table cellpadding="1" cellspacing="2" border="0">
<tr>
<td class="colTitle" align="center" colspan="4">
Da Titel2
</td>
</tr>
<tr>
<td class="colTitle" align="center" colspan="2">One
</td>
<td class="colTitle" align="center" colspan="2">Two
I
</td>
</tr>
<tr>
<td class="colSubTitle">Pe2</td>
<td class="colSubTitle">Ve2</td>
<td class="colSubTitle">Pe2</td>
<td class="colSubTitle">Ve2</td>
</tr>
<tr>
<td class="rowTitle">x2</td>
<td class="colVerbDef">y2</td>
<td class="rowTitle">z2</td>
<td class="colVerbDef">c2</td>
</tr>
<tr>
<td class="rowTitle">r2</td>
<td class="colVerbDef">t2</td>
<td class="rowTitle">z2</td>
<td class="colVerbDef">z2</td>
</tr>
</table>
</td>
</tr>
</tbody>
You can get the contents of the parent table's td elements using a direct path from the root:
/table/tbody/tr/td
The contents of those cells happen to be another table element, but you can strip those out with DOMDocument.
To get the inner tables' td elements only excluding the parents, you can look for tables that have a td parent, then select its tds:
//td/table//td
If I've misunderstood your question, please feel free to explain further and I will update.

How can I cleanly print a web page to a Generic/Txt Printer?

I have an web application that generates a small receipt format.
when printed to a generic/txt printer.. Nothing is printed to the sheet
Here is a sample of the print..
Removed
Please is there a way i could print this webpage to a generic/txt printer
Here is the html
<style>
body{
font-family:"Courier New", Courier, monospace;
font-size:13px;
}
.f1{
text-transform:uppercase;
display:block;
text-align:center;
}
.f2{
text-transform:uppercase;
display:block;
margin-left:10px;
}
.border_bottom{
border-bottom:2px dashed #000;
}
.border_top{
border-top:2px dashed #000;
}
.body_table{
border:1px dashed #CCCCCC;
padding:.5em;
}
</style>
</head>
<body onload="window.print();">
<table width="300" cellpadding="0" cellspacing="0" class="body_table">
<tr>
<td><span class="f1">Official Receipt</span></td>
</tr>
<tr>
<td><span class="f1">DreamWorks Pharmaceutical Industries Limited GH.</span></td>
</tr>
<tr>
<td><span class="f1">Plot 14 Blk 8A</span></td>
</tr>
<tr>
<td class="border_bottom"><span class="f1">0241093621</span></td>
</tr>
<tr>
<td class=""><span class="f2">RECEIPT NO.: 0241093621</span></td>
</tr>
<tr>
<td class=""><span class="f2">VAT REG #.: </span></td>
</tr>
<tr>
<td class=""><span class="f2">cashier.: </span></td>
</tr>
<tr>
<td class=""><span class="f2">date.: time: </span></td>
</tr>
<tr>
<td class="border_bottom"><span class="f2">customer.: time: </span></td>
</tr>
<tr>
<td>
<table width="98%" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="5%"><span class="f2">QTY</span></td>
<td width="60%"><span class="f2">item</span></td>
<td width="15"><span class="f2">price</span></td>
<td width="15"><span class="f2">amt.</span></td>
</tr>
<tr>
<td class="f2">52</td>
<td>MALAREX TABS</td>
<td>2.6</td>
<td>135.20</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="border_top border_bottom">
<table width="100%" cellpadding="0" cellspacing="0" align="left" id="print_table7">
<tr>
<Td class="ash_backg" width="53%"><span>Subtotal</span></Td>
<td width="47%" align="right">135.20</td>
</tr>
<tr>
<Td class="ash_backg"><span>Discount</span></Td>
<td align="right">0.00</td>
</tr>
<tr>
<Td class="ash_backg"><span>VAT</span></Td>
<td align="right">0.00</td>
</tr>
<tr>
<Td class="ash_backg"><span>Total Due</span></Td>
<td align="right">135.20</td>
</tr>
<tr>
<Td class="ash_backg"><span>Paid</span></Td>
<td align="right">135.20</td>
</tr>
<tr>
<Td class="ash_backg"><span>Change</span></Td>
<td align="right">0.00</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>Thank You dear customer</td>
</tr>
<tr>
<td>VAT Inclusive Where Applicable</td>
</tr>
</table>
</body>
Here's the Receipt Format HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/plain; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
#media screen{
body{
font-family:"Courier New", Courier, monospace;
font-size:13px;
}
.f1{
text-transform:uppercase;
display:block;
text-align:center;
}
.f2{
text-transform:uppercase;
display:block;
margin-left:10px;
}
.border_bottom{
border-bottom:2px dashed #000;
}
.border_top{
border-top:2px dashed #000;
}
.body_table{
border:1px dashed #CCCCCC;
padding:.5em;
}
}
#media print{
body{
font-family:"Courier New", Courier, monospace;
font-size:8px;
width:250px;
}
}
</style>
</head>
<body onload="window.print();">
<table width="300" cellpadding="0" cellspacing="0" class="body_table">
<tr>
<td><span class="f1">Official Receipt</span></td>
</tr>
<tr>
<td><span class="f1">DreamWorks Pharmaceutical Industries Limited GH.</span></td>
</tr>
<tr>
<td><span class="f1">Plot 14 Blk 8A</span></td>
</tr>
<tr>
<td class="border_bottom"><span class="f1">0241093621</span></td>
</tr>
<tr>
<td class=""><span class="f2">RECEIPT NO.: 0241093621</span></td>
</tr>
<tr>
<td class=""><span class="f2">VAT REG #.: </span></td>
</tr>
<tr>
<td class=""><span class="f2">cashier.: </span></td>
</tr>
<tr>
<td class=""><span class="f2">date.: time: </span></td>
</tr>
<tr>
<td class="border_bottom"><span class="f2">customer.: time: </span></td>
</tr>
<tr>
<td>
<table width="98%" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="5%"><span class="f2">QTY</span></td>
<td width="60%"><span class="f2">item</span></td>
<td width="15"><span class="f2">price</span></td>
<td width="15"><span class="f2">amt.</span></td>
</tr>
<tr>
<td class="f2">6</td>
<td>MALAREX TABS</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td class="f2">1</td>
<td>PARAFEN PLUS TAB.</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td class="f2">5</td>
<td>ASTHAX INHALER</td>
<td>5</td>
<td>25</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="border_top border_bottom">
<table width="100%" cellpadding="0" cellspacing="0" align="left" id="print_table7">
<tr>
<Td class="ash_backg" width="53%"><span>Subtotal</span></Td>
<td width="47%" align="right">25.00</td>
</tr>
<tr>
<Td class="ash_backg"><span>Discount</span></Td>
<td align="right">0.00</td>
</tr>
<tr>
<Td class="ash_backg"><span>VAT</span></Td>
<td align="right">0.00</td>
</tr>
<tr>
<Td class="ash_backg"><span>Total Due</span></Td>
<td align="right">25.00</td>
</tr>
<tr>
<Td class="ash_backg"><span>Paid</span></Td>
<td align="right">25.00</td>
</tr>
<tr>
<Td class="ash_backg"><span>Change</span></Td>
<td align="right">0.00</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>Thank You dear customer</td>
</tr>
<tr>
<td>VAT Inclusive Where Applicable</td>
</tr>
</table>
</body>
</html>
You can use CSS media types. Use one for the screen to make it look nice and one for print, to make it plain.
For example:
#media screen
{
p.test {font-family:verdana,sans-serif;font-size:14px;}
}
#media print
{
p.test {font-family:times,serif;font-size:10px;}
}
Yes, you can print the document as the above and you have to use the separate style sheet for the screen display and printing. CSS rules are:
#media screen
{
//Css
}
#media print{
#page { size:250px 375px; margin: 4px }
body{font-family:"Courier New", Courier, monospace; font-size:8px;}
.f1{text-transform:uppercase; display:block; text-align:center;}
.f2{text-transform:uppercase; display:block; margin-left:10px;}
.border_bottom{ border-bottom:2px dashed #000;}
.border_top{border-top:2px dashed #000;}
.body_table{border:1px dashed #CCCCCC; padding:.5em;}
}
In these you can describe the page size, colors and many more things Just Google the CSS Print specification and you would know more.
But, I think the another problem involved in your i.e. print using POS printer to print it. For that I would Like to suggest the way are:
Two simple ways to do it, depending on how much interference you're willing to accept in your interface.
Firstly, you can just use JavaScript to trigger your receipt page/iframe to print. This option is a little klunky, as it requires the cashier to confirm the print in the system dialogue.
But secondly, you always have the option of sharing each station's printer on the network. Your server-side component can print directly to it. And if it's a *nix server, it's pretty easy to do once each station's printer has added to / shared with the server. In PHP (with CUPs installed, I imagine):
// attempt to pipe to 'lp -d printername'
if (`echo "{$text}" | lp -d {$printer_name}`) {
// print successful
return true;
} else {
// print failed
return false;
}
For second method, If you're running a windows server, it's probably much more complicated.

Categories