Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

385
Visualizações
How do i make the jspdf pdf file changes everytime an <option> tag in HTML is choosen?

I'm sorry that my english is pretty bad, and i'm an absolute beginner, but how do i make this work

    <html>
  <title>form</title>
  <script type = "text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js"></script> 
<script type= "text/javascript">
   

   function genPDF() {
    var doc = new jsPDF();

doc.text(45,45, "burgerking");
doc.addImage(imgData, 'JPEG',0.25, 0.25, 210, 300);
doc.addPage();
doc.addImage(imgData, 'JPEG',0.25, 0.25, 210, 300);
doc.addPage();
doc.addImage(imgData, 'JPEG',0.25, 0.25, 210, 300);
if (document.getElementById("ice-cream").value == "choco") {
    doc.text(50,65, "please work")

}
else {
    doc.text(50,65, "knowing that you'll learn stuff when");
    doc.text(50,69, "failing miserably, you're filled with xd");

}


doc.save('form.pdf')
}
       

</script>


 <div>
<label>what kind of ice cream do you want?```<br>
<select id="ice-cream" onchange="genPDF()">```<br>
   <option value="vani"> Vanilla </option>```<br>
   <option value="choco"> Chocolate </option>```<br>
</select><br><br>
 </div>

obviously, the code wouldn't work, so could anyone please help ;-;

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This is working code. Did you check the imgData. That is breaking the code. I just commented and its working. Also check last page of the Pdf.

<html>
  <title>form</title>
  <script type = "text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js"></script> 
<script type= "text/javascript">
   

   function genPDF() {
    var doc = new jsPDF();

doc.text(45,45, "burgerking");
//doc.addImage(imgData, 'JPEG',0.25, 0.25, 210, 300);
doc.addPage();
//doc.addImage(imgData, 'JPEG',0.25, 0.25, 210, 300);
doc.addPage();
//doc.addImage(imgData, 'JPEG',0.25, 0.25, 210, 300);
alert(document.getElementById("ice-cream").value)
if (document.getElementById("ice-cream").value == "choco") {
    alert('ere');
    doc.text(50,65, "please work")
}
else {
    doc.text(50,65, "knowing that you'll learn stuff when");
    doc.text(50,69, "failing miserably, you're filled with xd");
}
doc.save('form.pdf')
}
       

</script>


 <div>
<label>what kind of ice cream do you want?```<br>
<select id="ice-cream" onchange="genPDF()">```<br>
   <option value="vani"> Vanilla </option>```<br>
   <option value="choco"> Chocolate </option>```<br>
</select><br><br>
 </div>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda