2 回答

TA貢獻1844條經驗 獲得超8個贊
將您的腳本移到</body>標記之前或下方,form它將起作用。
function sendToQuickPrinter(){
var text =
"<CENTER><MEDIUM2><?php echo $shop_name ?><BR>" +
"<CENTER><?php echo $display_date ?> <?php echo $display_time ?><BR><BR>" +
"Description Price<BR>" +
"<?php $i=0;while($i < $print_count){$i=$i+1; echo $p_name_array[$i].';; ;;'.$transaction_qty_array[$i].' @ '.number_format($p_price_array[$i],2).'<BR>';} ?>" +
"<BR>" +
"<CENTER>Sub-total $<?php echo number_format($subtotal,2) ?><BR>" +
"<CENTER>Tax $<?php echo number_format($subtax,2) ?><BR>" +
"<CENTER>Total $<?php echo number_format($item_total,2) ?><BR>" +
"<BR>" +
"<CENTER>Thank you for shopping with us, we appreciate your business!<BR>" +
"<CENTER><MEDIUM2> Have a great day!<BR>" +
"<BR>" +
"<CUT>" +
"DRAWER";
var textEncoded = encodeURI(text);
window.location.href="quickprinter://"+textEncoded;
document.frm2.submit() // !!!important- I auto submit frm2 below
}
//sendToQuickPrinter();
<form action="cart.php" name="frm2" method="post">
<input type="hidden" name="longitude" id="getlon" />
<input type="hidden" name="latitude" id="getlat" />
<input type="hidden" name="shop_name" value="<?php echo $shop_name ?>" />
</form>
<button id="print" click="sendToQuickPrinter();">Print</button>

TA貢獻1816條經驗 獲得超4個贊
更改document.frm2.submit()與document.forms["frm2"].submit()
function sendToQuickPrinter(){
var text =
"<CENTER><MEDIUM2><?php echo $shop_name ?><BR>" +
"<CENTER><?php echo $display_date ?> <?php echo $display_time ?><BR><BR>" +
"Description Price<BR>" +
"<?php $i=0;while($i < $print_count){$i=$i+1; echo $p_name_array[$i].';; ;;'.$transaction_qty_array[$i].' @ '.number_format($p_price_array[$i],2).'<BR>';} ?>" +
"<BR>" +
"<CENTER>Sub-total $<?php echo number_format($subtotal,2) ?><BR>" +
"<CENTER>Tax $<?php echo number_format($subtax,2) ?><BR>" +
"<CENTER>Total $<?php echo number_format($item_total,2) ?><BR>" +
"<BR>" +
"<CENTER>Thank you for shopping with us, we appreciate your business!<BR>" +
"<CENTER><MEDIUM2> Have a great day!<BR>" +
"<BR>" +
"<CUT>" +
"DRAWER";
var textEncoded = encodeURI(text);
window.location.href="quickprinter://"+textEncoded;
document.forms["frm2"].submit() // !!!important- I auto submit frm2 below
}
添加回答
舉報