marcosevaristo Posted August 15, 2021 Share Posted August 15, 2021 (edited) Hello I have a problem in my Script and I'm not able to solve it, it's the following: I want to create a button that prints several different receipts, several lunch orders on one page and I want them all to have a print button for printing the receipt below: #This is the Button# <button id="botaoPrint" class="btn_1">Imprimir Pedido <i class="icon-print-2" aria-hidden="true"></i></button></a> #The receipt# </center> <div> <div class="container"> <div style="margin: 0 auto;align-items: center;display: flex;flex-direction: row;flex-wrap: wrap;justify-content: center;" class="row justify-content-center "> <article class="col-md-4"> <div id="divImprimir" style="background-color: #fdfbe3;" class="boxed-md boxed-padded"> <?php $dataex = explode(' ', $data); $dataex[0] = explode('-', $dataex[0]); $dataex[0] = array_reverse($dataex[0]); $dataex[0] = implode('/', $dataex[0]); $dataformatada = $dataex[0].' - '.$dataex[1]; $nome = str_replace('%20', ' ', $nome); $nomeCliente = $nome; $telefoneformatado = formatPhone($telefone); $taxaPedido = Check::Real($valor_taxa); $valorTroco = Check::Real($valor_troco); $totalPedido = Check::Real($total); $resumoPedidosFormatado = str_replace('*', '', $resumo_pedidos); $resumoPedidosFormatado = str_replace('<b>', '', $resumoPedidosFormatado); $resumoPedidosFormatado = str_replace('</b>', '', $resumoPedidosFormatado); $telefoneEmpresaFormatado = formatPhone($telefone_empresa); echo "<b>".$nome_empresa."</b>"; echo ".\n <br />"; echo (!empty($end_rua_n_empresa) && !empty($end_bairro_empresa) && !empty($cidade_empresa) && !empty($end_uf_empresa) ? $end_rua_n_empresa.' <br /> '.$end_bairro_empresa : 'Defina_um_endereço').' - '.$cidade_empresa.' - '.$end_uf_empresa; echo "\n <br />"; echo "Telefone: {$telefoneEmpresaFormatado}"; echo "\n <br />"; echo "\n <br />"; echo "<b>PEDIDO: #{$codigo_pedido}</b>\n <br />"; echo "{$dataformatada} <br />"; echo "\n <br />"; echo "-----------------------------"."\n <br />"; if($opcao_delivery != 'true'): echo "{$msg_delivery_false}\n <br />"; echo "Observações: {$name_observacao_mesa}\n <br />"; else: echo "Rua: {$rua}, Nº {$unidade}\n <br />"; echo "Bairro: {$bairro}\n <br />"; echo "Cidade: {$cidade} - {$uf}\n <br />"; echo "Complemento: {$complemento}\n <br />"; echo "Observação: {$observacao}\n <br />"; endif; echo "-----------------------------"."\n <br />"; echo "\n <br />"; echo "DADOS DO CLIENTE: <br />"; echo "NOME: {$nomeCliente}\n <br />"; echo "TEL: {$telefoneformatado}\n <br />"; echo "-----------------------------"."\n <br />"; echo "\n <br />"; echo "RESUMO DO PEDIDO: <br />"; echo "{$resumoPedidosFormatado}"; echo "-----------------------------"."\n <br />"; echo "PAGAMENTO: {$forma_pagamento}\n <br />"; echo (!empty($sub_total) || $sub_total != '0.00' ? "SUBTOTAL: R$ ".Check::Real($sub_total)." \n <br />" : "" ); if(!empty($desconto) && $desconto != 0): echo "DESCONTO: {$desconto}% \n <br />"; endif; if($valor_taxa != '0.00'): echo "DELIVERY: R$ {$taxaPedido}\n <br />"; endif; echo "TOTAL: R$ {$totalPedido} \n <br />"; if(!empty($valor_troco) && $valor_troco != '0.00'): echo "TROCO PARA: R$ {$valorTroco}\n <br />"; endif; echo "-----------------------------"." \n <br />"; echo "\n <br />"; echo "***OBRIGADO E BOM APETITE*** \n <br />"; ?> </div> </article> </div> </div> </div> <center> ----------------------------------------------------------------- *COMMAND TO PRINT* <script type="text/javascript" charset="utf-8"> $(document).ready(function(){ $('#botaoPrint2').click(function(){ $('#divImprimir').printThis({ doctypeString: '<meta charset="utf-8">', importStyle: true, base: false, }); }); }); </script> Edited August 15, 2021 by Barand code tags added Quote Link to comment Share on other sites More sharing options...
Barand Posted August 15, 2021 Share Posted August 15, 2021 Please use the <> button in the toolbar when posting code. I have done it for you this time. Quote Link to comment Share on other sites More sharing options...
requinix Posted August 15, 2021 Share Posted August 15, 2021 You've said that you have a problem but you haven't said what the problem is. Quote Link to comment Share on other sites More sharing options...
marcosevaristo Posted August 15, 2021 Author Share Posted August 15, 2021 the problem is that only the first button works, the other buttons don't open the print function Quote Link to comment Share on other sites More sharing options...
requinix Posted August 15, 2021 Share Posted August 15, 2021 <button id="botaoPrint" IDs must be unique on the page. If you want more than one print button then you cannot use IDs for them. Quote Link to comment Share on other sites More sharing options...
marcosevaristo Posted August 15, 2021 Author Share Posted August 15, 2021 Yes my friend!! but i don't know what i should do to replace the id so the button can open for all receipts!! Please help me! Quote Link to comment Share on other sites More sharing options...
marcosevaristo Posted August 15, 2021 Author Share Posted August 15, 2021 this is the code that prints, i fixed it is *botaoprint* what should i do to fix this bug please help me!! <script type="text/javascript" charset="utf-8"> $(document).ready(function(){ $('#botaoPrint').click(function(){ $('#divImprimir').printThis({ doctypeString: '<meta charset="utf-8">', importStyle: true, base: false, }); }); }); </script> Quote Link to comment Share on other sites More sharing options...
requinix Posted August 15, 2021 Share Posted August 15, 2021 Do not use an ID to identify the buttons. Find another solution. Consider learning more about HTML while you're at it. Hint: the best solution is something that you're already using elsewhere in the markup. Oh. And please don't solicit help through PMs. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.