I have been trying to print a particular div with ng-repeat using a pos bluetooth printer using Javascript.
function sendToQuickPrinterChrome(){
var qtylength = document.getElementById("totalQtyLength").outerText;
var objDiv = document.getElementById("div_print").outerText;
var dt = document.getElementById("Date").textContent;
var qty = document.getElementById("totalQty").textContent;
var total = document.getElementById("total").textContent;
var order = document.getElementById("order").textContent;
var orderNo = document.getElementById("orderNo").textContent;
var _orderNo = "<CENTER> <BOLD>" + orderNo.trim() + "<BR>";
var tokenNo = document.getElementById("tokenNo").textContent;
var tokenNoVal = "<CENTER> <BOLD>" + tokenNo + "<BR>";
var orderdet = "<CENTER> <BOLD>" + order;
var a = "<CENTER> <BOLD>" + dt;
var totalVal = "<CENTER> <BOLD>" + total;
var quantity = "<CENTER><BOLD>" + qty.trim();
var objDiv = "<CENTER><Big>Company <BR>" + "<CENTER> <BOLD>Order Summary <BR>" + _orderNo + tokenNoVal + a +"<BR>"+ order + qty.trim() + totalVal;
var textEncoded = encodeURI(objDiv );
window.location.href="intent://"+textEncoded+"#Intent;scheme=quickprinter;package=pe.diegoveloper.printerserverapp;end;";
}
Order is a div with the product name and price. When it is to be printed in the POS reciept printer, there is a misalignment. We are using Quick printer android app to print as it is an old POS printer. The app is used in a Tablet
Related
I made a CGPA-SGPA calculator and I cannot get the value with refresh.
When I refresh and check the value it get feed
but not getting value without refresh.
var credit_1001 = document.querySelector('#credit_1001')
var grade_1001 = document.querySelector('#grade_1001')
var credit_1002 = document.querySelector('#credit_1002')
var grade_1002 = document.querySelector('#grade_1002')
var credit_1003 = document.querySelector('#credit_1003')
var grade_1003 = document.querySelector('#grade_1003')
var credit_1004 = document.querySelector('#credit_1004')
var grade_1004 = document.querySelector('#grade_1004')
var credit_1008 = document.querySelector('#credit_1008')
var grade_1008 = document.querySelector('#grade_1008')
var credit_1009 = document.querySelector('#credit_1009')
var grade_1009 = document.querySelector('#grade_1009')
//btn and result S1
var btn_check = document.querySelector('#check_s1')
var result_s1 = document.querySelector('#result_s1')
//btn click S1
var total_s1_credit = parseInt(credit_1001.value) + parseInt(credit_1002.value) + parseInt(credit_1003.value) + parseInt(credit_1004.value) + parseInt(credit_1008.value) + parseInt(credit_1009.value)
var got_s1_marks = parseInt(credit_1001.value) * parseInt(grade_1001.value) + parseInt(credit_1002.value) * parseInt(grade_1002.value) + parseInt(credit_1003.value) * parseInt(grade_1003.value) + parseInt(credit_1004.value) * parseInt(grade_1004.value) + parseInt(credit_1008.value) * parseInt(grade_1008.value) + parseInt(credit_1009.value) * parseInt(grade_1009.value)
btn_check.addEventListener('click', () => {
result_s1.innerText = " S1 SGPA " + got_s1_marks / total_s1_credit
console.log("S1 Total Credit = " + total_s1_credit)
console.log("S1 Got Marks = " + got_s1_marks)
console.log("S1 SGPA = " + result_s1.innerText)
})
You need to get the values for your calculation inside of the click handler, right now you get them before the click, and then use (the old values) when the click happens
btn_check.addEventListener('click', () => {
//btn click S1
var total_s1_credit = parseInt(credit_1001.value) + parseInt(credit_1002.value) + parseInt(credit_1003.value) + parseInt(credit_1004.value) + parseInt(credit_1008.value) + parseInt(credit_1009.value)
var got_s1_marks = parseInt(credit_1001.value) * parseInt(grade_1001.value) + parseInt(credit_1002.value) * parseInt(grade_1002.value) + parseInt(credit_1003.value) * parseInt(grade_1003.value) + parseInt(credit_1004.value) * parseInt(grade_1004.value) + parseInt(credit_1008.value) * parseInt(grade_1008.value) + parseInt(credit_1009.value) * parseInt(grade_1009.value)
result_s1.innerText = " S1 SGPA " + got_s1_marks / total_s1_credit
console.log("S1 Total Credit = " + total_s1_credit)
console.log("S1 Got Marks = " + got_s1_marks)
console.log("S1 SGPA = " + result_s1.innerText)
})
I have learned how to automate google form filling using google sheet and app script. After many trial and error to apply the concept and automate it on simple google forms i have created, it worked absolutely fine.
But when I applied on the google form (which i seriously want to automate), everything works fine except the last line of code i.e. UrlFetchApp which brings google form link and data together and submit the form using "post" method but it's not working.
When i commented this line rest of the code executed without any error but this line is making my effort fail.
google form link for which i have created this code: https://docs.google.com/forms/d/e/1FAIpQLSc1uSOspwlen5Tcs0ccTxE4eia-scw3aVUwAsrVMdQBpk5ydA/viewform
function QC_form_fill() {
var wrkBk = SpreadsheetApp.getActiveSpreadsheet();
var wrkSht = wrkBk.getSheetByName("Qdata");
var formURL =""
var formData =""
var sdate = "";
var stime = "";
var mname = "";
var board = "";
var eclas = "";
var batch = "";
var slecture = "";
var sfaculty = "";
var ati1 = "";
var ta1 = "";
var ta2 = "";
var ta3 = "";
var sopen = "";
var stengage = "";
var teachpace = "";
var chtresp = "";
var tmmanmnt = "";
var vomod = "";
var sgrammar = "";
var qppt = "";
var fhndwrtng = "";
var drssup = "";
var lobjective = "";
var expstyl = "";
var sflow = "";
var cntnacc = "";
var demos = "";
var ati2 = "";
var poll = "";
var la = "";
var hw = "";
var prlfcd = "";
var sggstn = "";
var noOfRows = wrkSht.getRange("AI1").getDisplayValue();
for (i=2; i<=noOfRows; i++)
{
sdate =wrkSht.getRange("A"+i).getDisplayValue();
stime =wrkSht.getRange("B"+i).getDisplayValue();
mname =wrkSht.getRange("C"+i).getDisplayValue();
board =wrkSht.getRange("D"+i).getDisplayValue();
eclas =wrkSht.getRange("E"+i).getDisplayValue();
batch =wrkSht.getRange("F"+i).getDisplayValue();
slecture =wrkSht.getRange("G"+i).getDisplayValue();
sfaculty =wrkSht.getRange("H"+i).getDisplayValue();
ati1 =wrkSht.getRange("I"+i).getDisplayValue();
ta1 =wrkSht.getRange("J"+i).getDisplayValue();
ta2 =wrkSht.getRange("K"+i).getDisplayValue();
ta3 =wrkSht.getRange("L"+i).getDisplayValue();
sopen =wrkSht.getRange("M"+i).getDisplayValue();
stengage =wrkSht.getRange("N"+i).getDisplayValue();
teachpace =wrkSht.getRange("O"+i).getDisplayValue();
chtresp =wrkSht.getRange("P"+i).getDisplayValue();
tmmanmnt =wrkSht.getRange("Q"+i).getDisplayValue();
vomod =wrkSht.getRange("R"+i).getDisplayValue();
sgrammar =wrkSht.getRange("S"+i).getDisplayValue();
qppt =wrkSht.getRange("T"+i).getDisplayValue();
fhndwrtng =wrkSht.getRange("U"+i).getDisplayValue();
drssup =wrkSht.getRange("V"+i).getDisplayValue();
lobjective =wrkSht.getRange("W"+i).getDisplayValue();
expstyl =wrkSht.getRange("X"+i).getDisplayValue();
sflow =wrkSht.getRange("Y"+i).getDisplayValue();
cntnacc =wrkSht.getRange("Z"+i).getDisplayValue();
demos =wrkSht.getRange("AA"+i).getDisplayValue();
ati2 =wrkSht.getRange("AB"+i).getDisplayValue();
poll =wrkSht.getRange("AC"+i).getDisplayValue();
la =wrkSht.getRange("AD"+i).getDisplayValue();
hw =wrkSht.getRange("AE"+i).getDisplayValue();
prlfcd =wrkSht.getRange("AF"+i).getDisplayValue();
sggstn =wrkSht.getRange("AG"+i).getDisplayValue();
formURL ="https://docs.google.com/forms/d/e/1FAIpQLSc1uSOspwlen5Tcs0ccTxE4eia-scw3aVUwAsrVMdQBpk5ydA/formResponse?pageHistory=0,1"
formData= "&entry.1809185170=" + sdate + "&entry.772722605=" + stime + "&entry.1721230767=" + mname + "&entry.1024240207=" + board + "&entry.1132896225=" + eclas +"&entry.134507089="+ batch + "&entry.1349051916=" + slecture + "&entry.15763511=" +sfaculty + "&entry.1915124723=" + ati1 + "&entry.1154530333=" + ta1 + "&entry.1450881147=" + ta2 + "&entry.1627300385=" + ta3 + "&entry.928964249=" + sopen + "&entry.103830616=" + stengage + "&entry.1749915137=" + teachpace + "&entry.1879781398=" + chtresp + "&entry.1210552578=" + tmmanmnt + "&entry.1659325247=" + vomod + "&entry.377007890=" + sgrammar + "&entry.1207703694=" + qppt + "&entry.960993930=" + fhndwrtng + "&entry.343485399=" + drssup + "&entry.1988728268=" + lobjective + "&entry.1019203670=" + expstyl + "&entry.222077844=" + sflow + "&entry.465124407=" + cntnacc + "&entry.1299956408=" + demos + "&entry.956891355=" + ati2 + "&entry.60052266=" + poll + "&entry.125539625=" + la + "&entry.1193513376=" + hw + "&entry.705255491=" + prlfcd + "&entry.121026171=" +sggstn
var finalURL = formURL + formData
var options = {
"method" : "post"
};
UrlFetchApp.fetch(finalURL, options);
}
}
I cant solve this homework that needs to ask the user to enter student marks and output the minimum mark of the student, can someone please help me solve this problem:
<script>
function getMarks() {
var marks = prompt('Type the students marks, seperate each student mark with comma, do not write the percentage mark % .').split(',');
return marks;
}
var studentMarks = getMarks();
var arrayLength = studentMarks.length;
var studentNumber = 0;
var msg = '';
var i;
for (i = 0; i < arrayLength; i++) {
studentNumber = (i + 1);
msg += 'student ' + studentNumber + ': ';
msg += studentMarks[i] + '%' + '<br />';
} document.getElementById('marks').innerHTML = msg; document.getElementById('marke').innerHTML = math.min.apply(null, studentMarks) + '%';
</script>
I will do that in the following way:
function getMarks() {
var marks = prompt('Type the students marks, seperate each student mark with comma, do not write the percentage mark % .');
return marks.split(',').map(n => Number(n));
}
var marksArray = getMarks();
var studentMarks = Math.min(...marksArray);
var position = marksArray.indexOf(studentMarks);
var msg = 'Student ' + Number(position + 1) + ': ';
document.getElementById('marks').innerHTML = msg + studentMarks + '%';
<p id="marks"></p>
The user should be able to enter in an integer and see the base, squared, and cubed result of that number. The base result should be listed under the "base" header, the squared result should be listed under the "squared" header and the cubed result should be listed under the "cubed" result. However, my output is listed all results under the "base" header. How can I make the results be listed under the related headers? This is what I have:
var $ = function (id) {
return document.getElementById(id);
}
var calculate = function () {
//Get the input from the user and assign it to the userInput variable
var integer = $("integer").value;
var header = "Base" + " " + "Square" + " " + "Cubed" + "\n";
var squared = "";
var cubed = "";
var base = "";
var displayOutput;
for (var i = 1; i <= integer; i++) {
base += i + "\n";
squared += i * i + "\n";
cubed += i * i * i + "\n";
displayOutput = base + squared + cubed;
}
$("output").value = header + displayOutput;
}
var form_reset = function () {
$("output").value = "";
$("integer").value = "";
}
//Assign event handlers to their events
window.onload = function () {
$("powers").onclick = calculate;
$("clear").onclick = form_reset;
}
It all depends on the output. Trying to stay as close as possible to your code, seems you are inserting your resulting displayOutput string into a textarea control. If you want to keep it that way, try tabs (\t) to separate your columns, and only a new line at the end (\n). Also, I noticed you were concatenating every column (base, square, and cubed) on every iteration, so I removed that. Here's the result:
var $ = function (id) {
return document.getElementById(id);
};
var calculate = function () {
//Get the input from the user and assign it to the userInput variable
var integer = $("integer").value;
var header = "Base" + " " + "Square" + " " + "Cubed" + "\n";
var squared = "";
var cubed = "";
var base = "";
var displayOutput = "";
for (var i = 1; i <= integer; i++) {
base = i + "\t";
squared = i * i + "\t";
cubed = i * i * i + "\n";
displayOutput += base + squared + cubed;
}
$("output").value = header + displayOutput;
};
var form_reset = function () {
$("output").value = "";
$("integer").value = "";
};
//Assign event handlers to their events
window.onload = function () {
$("powers").onclick = calculate;
$("clear").onclick = form_reset;
$("theform").onsubmit = function() { return false; };
};
The script works great for adding items on invoice however i cant figure how to convert the data using .toFixed(2) to show $10.00 instead of 10. I get an error every time I try to add .toFixed(2) . thank you
<script type="text/javascript">
function myFunction() {
var answer = document.getElementById('total');
var x = document.getElementById('itemprice1');
var y = document.getElementById('itemprice2');
var z = document.getElementById('itemprice3');
var w = document.getElementById('itemprice4');
var taxt = document.getElementById('taxtot');
var thetot = document.getElementById('thetot');
// parseFloat converts to values, otherwise you'll concatenate the strings.
answer.value = parseFloat("0" + x.value) + parseFloat("0" + y.value) + parseFloat("0" + z.value) + parseFloat("0" + w.value);
}
function myFunction1() {
var answer = document.getElementById('total');
var taxt = document.getElementById('taxtot');
var thetot = document.getElementById('thetot');
thetot.value = parseFloat("0" + answer.value) + parseFloat("0" + taxt.value);
if (thetot > "0") {
{
//function myFunction2()
var taxt = document.getElementById('taxtot');
var tx1 = document.getElementById('tax1');
var tx2 = document.getElementById('tax2');
var tx3 = document.getElementById('tax3');
var tx4 = document.getElementById('tax4');
var x = document.getElementById('itemprice1');
var y = document.getElementById('itemprice2');
var z = document.getElementById('itemprice3');
var w = document.getElementById('itemprice4');
var answer = document.getElementById('total');
taxt.value = parseFloat("0" + tx1.value) * ("0" + x.value) + parseFloat("0" + tx2.value) * ("0" + y.value) + parseFloat("0" + tx3.value) * ("0" + z.value) + parseFloat("0" + tx4.value) * ("0" + w.value);
}
}
}
</script>
Presumably your controls are in a form, so you can reference them simply using their name in the form. You can also convert strings to numbers using unary +:
function myFunction(formId) {
var f = document.getElementById(formId);
var answer = f.total;
var x = +f.itemprice1.value;
var y = +f.itemprice2.value;
var z = +f.itemprice3.value;
var w = +f.itemprice4.value;
var taxt = f.taxtot;
var thetot = f.thetot;
// Presumably here is where you want to use toFixed
answer.value = '$' + (x + y + z + w).toFixed(2);
}
function to_dollar_string(amount)
{
return "$" + amount.toFixed(2);
}
to_dollar_string(10);
=> "$10.00"
to_dollar_string(10.567);
=> "$10.57"