I have forms and they all work through onsubmit with the same script. I had to make one of the forms so that when I clicked on a button, in addition to sending data, a new page will open to the user where the PDF file will be.

here is the form:

<script> function validate() { var name = document.getElementById("name"); var email = document.getElementById("email"); event.preventDefault(); if(!name.value) { return false; } if(!email.value) { return false; } window.open('*********/journal.pdf','_blank'); } </script> 
 <form action="#" method="post" class="form-style1 form1" onsubmit="return sendForm(1);"> <input type="text" id="name" name="name" placeholder="Ваше имя" onkeyup="isNotEmpty(this)" required=""> <input type="text" id="email" class="email" name="email" placeholder="Ваша почта" onkeyup="isNotEmpty(this)" required=""> <input type="hidden" name="form_name" value=""> <input type="submit" value="Cкачать пример журнала" class="btn1" onclick="validate(); return true;"> </form> 

At the moment, sendForm is not working, I suppose, because after it is triggered, a window should appear on the successful sending!

  • you by clicking on the button cancel the remaining events event.preventDefault (); - does not allow fulfilled submission. call sendForm (1) in the validation function if successful - Taarim

0