armasmike
asked on
2 buttons that run deferent parts of a javascript file ?
I am trying to print labels using a DYMO Developer SDK it uses javascripts here is my files PrintMeThatLabel2.js
I got most of it working with the help for you all. I have a from the user query sql then save the info to a json then the PrintMeThatLabel2.js get that info and prints the label. If the query get 10 recorded it prints 10 labels Great!
But if I want to print 1 label out of the 10 I don't know how to push the 1 json to the PrintMeThatLabel2.js for printing.
I got most of it working so when I press Print me button it reloads the json array with just 1 recorded then I have to click the big print button at the top to print just that 1 recorded.
If the user then want to print them ALL 10 he/she will have to query the db again for it to load all the recorded in to the json array then click the big print button to run PrintMeThatLabel2.js and print.
I am trying to not have the user rerun the page to print all label ones the just pick one of the record to print.
so 2 buttons 1 prints all the recorded and 1 prints just the one he/she picked.
Most of you will recognize this code
so right now if I click the "Print me" Button, I should rename it to "Select me".
Then click the big print button at the top it work and prints just that one I wanted.
Because the "Print me" Button outputting the new json data
Then in the PrintMeThatLabel2.js that "mike" data is getting loaded and printed.
The PrintMeThatLabel2.js has a lot of onloads and I think this what stopping me from printing all the data or just print 1 row of data.
Is there a way to change PrintMeThatLabel2.js to do a IF user click Print all button on main page then print all the data in json.
If user click Print me button only print the json data from the row the user picked.
Do this make senses ?
I got most of it working with the help for you all. I have a from the user query sql then save the info to a json then the PrintMeThatLabel2.js get that info and prints the label. If the query get 10 recorded it prints 10 labels Great!
But if I want to print 1 label out of the 10 I don't know how to push the 1 json to the PrintMeThatLabel2.js for printing.
I got most of it working so when I press Print me button it reloads the json array with just 1 recorded then I have to click the big print button at the top to print just that 1 recorded.
If the user then want to print them ALL 10 he/she will have to query the db again for it to load all the recorded in to the json array then click the big print button to run PrintMeThatLabel2.js and print.
I am trying to not have the user rerun the page to print all label ones the just pick one of the record to print.
so 2 buttons 1 prints all the recorded and 1 prints just the one he/she picked.
Most of you will recognize this code
<html>
<head>
<title>Search</title>
<link rel="stylesheet" type="text/css" href="PrintMeThatLabel.css" />
<script src = "cookie.js" type="text/javascript"> </script>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script src = "http://www.labelwriter.com/software/dls/sdk/js/DYMO.Label.Framework.3.0.js" type="text/javascript" charset="UTF-8"> </script>
<script src = "PrintMeThatLabel2.js" type="text/javascript" charset="UTF-8"> </script>
<style type=text/css>
.text {color: #000; font-family:Arial, Helvetica, sans-serif }
.head {color: #000; font-family:Arial, Helvetica, sans-serif }
.input {display:none;}
.tftable {font-size:12px;color:#333333;width:100%;border-width: 1px;border-color: #729ea5;border-collapse: collapse;}
.tftable th {font-size:12px;background-color:#acc8cc;border-width: 1px;padding: 8px;border-style: solid;border-color: #729ea5;text-align:left;}
.tftable tr {background-color:#d4e3e5;}
.tftable td {font-size:12px;border-width: 1px;padding: 8px;border-style: solid;border-color: #729ea5;}
.tftable tr:hover {background-color:#ffffff;}
</style>
</head>
<body>
<div class=text align="center">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" >
<span class=text>Enter Work Order #: </span>
<input type="text" name="Work_Order" length="30" value="">
<input type="submit" name="submit" value = "Search">
</form>
</div>
<div id="wrapper">
<div class='labelDesignArea'>
<label for="printersSelect">Printer:</label>
<select id="printersSelect"></select>
<button id="printButton">Print</button>
<div class='printerSettings'>
<a href='javascript:void(0)' style='visibility: hidden' id='printerSettingsButton'>Printer location (url)</a>
<div style='visibility: hidden id='printerSettingsDiv'>
<label style='visibility: hidden' for='printerUriTextBox'></label>
<input style='visibility: hidden' type='text' id='printerUriTextBox'></input>
<button style='visibility: hidden' id='addPrinterUriButton'>Add</button>
<button style='visibility: hidden'id='clearPrinterUriButton'>Clear</button>
</div>
</div>
</div>
</div>
<?php
ini_set("display_errors",1);
error_reporting(E_ALL);
if(isset($_POST['submit']))
{
$UsrWorkOrder = $_POST['Work_Order'];
//db connect info
include 'conn.php';
//Where the query are stored
include 'Query.php';
$result_Vis = odbc_exec($conn_Vis,$sql_Vis); // Get Data From Result
while($row2 = odbc_fetch_array($result_Vis))
{
//Store the data in the new array
$result_cor1db01_2 = odbc_exec($conn_cor1db01_2,$sql_cor1db01_2); // Get Data From Result
$json = array();
echo "<div><table class='tftable'><tbody><tr>";
Echo "<tr><th>Work Order</th><th>Part Number</th><th>Description</th><th>Mfg Lot Number</th><th>Cable Length</th><th>Test Results A</th><th>Test Results B</th></tr>";
$num_rows = odbc_num_rows($result_cor1db01_2);
while($row3 = odbc_fetch_array($result_cor1db01_2))
{
//This stores the data
$Serial_No = $row3["Serial No"];
$Barcode = $row3["Work Order No"]."-". $row3["Serial No"];
$part = $row2["PART_X"];
$DESCR = $row2["DESCR_X"];
$MFG = $row3["Work Order No"]."-". $row3["Serial No"];
$Cable_Length = $row3["ValueInches"];
IF(number_format($row3["Value1"],2)[0] < "1"){
$Test_A = substr(number_format($row3["Value1"],2), 1);
}Else{
$Test_A = number_format($row3["Value1"],2);
}
IF(number_format($row3["Value2"],2)[0] < "1"){
$Test_B = substr(number_format($row3["Value2"],2), 1);
}Else{
$Test_B = number_format($row3["Value2"],2);
}
// put all the data in to a json array for batch printing labels.
$json []= array (
'Serial_No' => $Serial_No,
'Barcode' => $Barcode,
'part' => $part,
'DESCR' => $DESCR,
'MFG' => $MFG,
'Cable_Length' => $Cable_Length,
'Test_A' => $Test_A,
'Test_B' => $Test_B
);
// Echo "<br><br><img src=barcode.php?codetype=Code128B&size=80&text=".$row3["Work Order No"]."-". $row3["Serial No"] ." />";
Echo "<td>".$row3["Work Order No"]."-". $row3["Serial No"]."</td>";
Echo "<td>".$part."</td>";
Echo "<td>".$DESCR."</td>";
Echo "<td>" .$row3["Work Order No"]."-". $row3["Serial No"]."</td>";
Echo "<td>". $row3["ValueInches"]."</td>";
IF(number_format($row3["Value1"],2)[0] < "1"){
Echo "<td>".substr($row3["SS1"], -1)." " .substr(number_format($row3["Value1"],2), 1)."</td>";
}Else{
Echo "<td>".substr($row3["SS1"], -1)." " .number_format($row3["Value1"],2)."</td>";
}
IF(number_format($row3["Value2"],2)[0] < "1"){
Echo "<td>".substr($row3["SS2"], -1)." " .substr(number_format($row3["Value2"],2), 1)."</td> ";
}Else{
Echo "<td>".substr($row3["SS2"], -1)." " .number_format($row3["Value2"],2)."</td>";
}
echo "<td><button data-json='$Serial_No' id='printONEButton' class='printme'>Print Me</button></td></tr>";
//Echo "Test Results: ".substr($row3["SS1"], -1)." " .number_format($row3["Value1"],2)."<br>";
//Echo "Test Results: ".substr($row3["SS2"], -1)." " .number_format($row3["Value2"],2)."<br>";
}
//$printMe= json_encode($json);
//echo json_encode($json);
echo "<br>".$num_rows ." Rows<br><br>";
Echo "</tbody></table></div>";
}
?>
<script type="text/javascript">
$(function()
{
$('button.printme').on('click',function()
{
var json = $(this).data('json');
var mike = $('#backup').text();
var objMike = JSON.parse(mike);
//console.log(mike2);
var NewMike = objMike.filter(function(ss)
{
return ss.Serial_No == json;
});
console.log(NewMike);
var UpdateJson = JSON.stringify(NewMike)
$('#mike').text(UpdateJson);
$('#printONEButton').click
});
});
</script>
<?php
odbc_close($conn_cor1db01_2);
odbc_close($conn_Vis);
}
?>
<!-- This is storing the Json data then this gets pulled in to the PrintMeThatLabel.js -->
<div id='backup' style="display: none;" name='backup'><?php echo json_encode($json); ?> </div>
<div id='mike' name='mike'>null</div>
</body>
</html>
so right now if I click the "Print me" Button, I should rename it to "Select me".
Then click the big print button at the top it work and prints just that one I wanted.
Because the "Print me" Button outputting the new json data
<div id='mike' name='mike'>null</div>
Then in the PrintMeThatLabel2.js that "mike" data is getting loaded and printed.
The PrintMeThatLabel2.js has a lot of onloads and I think this what stopping me from printing all the data or just print 1 row of data.
Is there a way to change PrintMeThatLabel2.js to do a IF user click Print all button on main page then print all the data in json.
If user click Print me button only print the json data from the row the user picked.
Do this make senses ?
ASKER
uuuu ok so
goes in the PrintMeThatLabel2.js I put it right under
then I put
in my main page here
I get a SCRIPT5009: 'getObjects' is not defined in the console
function getObjects(obj, key, val) {
var objects = [];
for (var i in obj) {
if (!obj.hasOwnProperty(i)) continue;
if (typeof obj[i] == 'object') {
objects = objects.concat(getObjects(obj[i], key, val));
} else if (i == key && obj[key] == val) {
objects.push(obj);
}
}
return objects;
}
goes in the PrintMeThatLabel2.js I put it right under
var mike = document.getElementById('mike').innerText;
//This is parse the json data.
var obj = jQuery.parseJSON(mike);
then I put
getObjects(TestObj, 'Serial_No', json);
in my main page here
<script type="text/javascript">
$(function()
{
$('button.printme').on('click',function()
{
var json = $(this).data('json');
var mike = $('#backup').text();
var objMike = JSON.parse(mike);
//console.log(mike2);
var NewMike = objMike.filter(function(ss)
{
return ss.Serial_No == json;
});
console.log(NewMike);
var UpdateJson = JSON.stringify(NewMike)
$('#mike').text(UpdateJson);
getObjects(TestObj, 'Serial_No', json);
});
});
</script>
I get a SCRIPT5009: 'getObjects' is not defined in the console
ASKER
so I made some changes and going away from the Print Me button.
I have added a
the css is
so the user know they clicked on a row. Then added the Data-json'$Seral_No' to the <tr> like
So then I can filter and out put the row the user picked to a json
But how to I append to the UpdateJson every time the user keeps clicking
So if user click Searl no 001 the json looks like this
{"Serial_No":"001","Barcod e":"M12334 0-050","pa rt":"F0698 4-0035","D ESCR":"BAC C69CCC0035 J\/BOEIN, REV R","MFG":"M123340-050","Ca ble_Length ":"35 Inches","Test_A":".10","Te st_B":".04 "}
and if they click 001 and 005 and 010
the json need to append to each click like
{"Serial_No":"001","Barcod e":"M12334 0-050","pa rt":"F0698 4-0035","D ESCR":"BAC C69CCC0035 J\/BOEIN, REV R","MFG":"M123340-050","Ca ble_Length ":"35 Inches","Test_A":".10","Te st_B":".04 "},{"Seria l_No":"005 ","Barcode ":"M123340 -050","par t":"F06984 -0035","DE SCR":"BACC 69CCC0035J \/BOEIN, REV R","MFG":"M123340-050","Ca ble_Length ":"35 Inches","Test_A":".10","Te st_B":".04 "},{"Seria l_No":"010 ","Barcode ":"M123340 -050","par t":"F06984 -0035","DE SCR":"BACC 69CCC0035J \/BOEIN, REV R","MFG":"M123340-050","Ca ble_Length ":"35 Inches","Test_A":".10","Te st_B":".04 "}
and if they re click the serial no 001 again it removes it form the json
I have added a
<script>
$( function() {
$('tr').click( function() {
$(this).toggleClass('on');
} )
});
</script>
the css is
tr.on {
background-color: red;
}
so the user know they clicked on a row. Then added the Data-json'$Seral_No' to the <tr> like
Echo "<tr data-json='$Serial_No'><td >".$row3["Work Order No"]."-". $row3["Serial No"]."</td>";
Echo "<td>".$part."</td>";
Echo "<td>".$DESCR."</td>";
Echo "<td>" .$row3["Work Order No"]."-". $row3["Serial No"]."</td>";
Echo "<td>". $row3["ValueInches"]."</td>";
IF(number_format($row3["Value1"],2)[0] < "1"){
Echo "<td>".substr($row3["SS1"], -1)." " .substr(number_format($row3["Value1"],2), 1)."</td>";
}Else{
Echo "<td>".substr($row3["SS1"], -1)." " .number_format($row3["Value1"],2)."</td>";
}
IF(number_format($row3["Value2"],2)[0] < "1"){
Echo "<td>".substr($row3["SS2"], -1)." " .substr(number_format($row3["Value2"],2), 1)."</td> ";
}Else{
Echo "<td>".substr($row3["SS2"], -1)." " .number_format($row3["Value2"],2)."</td>";
}
So then I can filter and out put the row the user picked to a json
var NewMike = objMike.filter(function(ss)
{
return ss.Serial_No == UserPick;
});
console.log(NewMike);
var UpdateJson = JSON.stringify(NewMike)
But how to I append to the UpdateJson every time the user keeps clicking
So if user click Searl no 001 the json looks like this
{"Serial_No":"001","Barcod
and if they click 001 and 005 and 010
the json need to append to each click like
{"Serial_No":"001","Barcod
and if they re click the serial no 001 again it removes it form the json
ASKER
I need to use a push to append to the end of the
cant it that working yet
UpdateJson
cant it that working yet
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
So if I have:
Open in new window
Ok, so obj has the full set.
Here's a function for JSON
Open in new window
So from that data set you could use:
Open in new window
And get the one result which you can pass to your function rather than having it always generate the JSON from a static location.