Why is onClick working before submit?

  • 0
    Chrome works the way I need it, first it submits the form and then goes away by onClick, but the form is not sent from the phone, just a redirect. How to fix it?
    <table border="0" width="100%" id="table1" cellspacing="1" cellpadding="2">
    <tr><b>ВАШ ТЕКСТ</b><font color="red">*</font>:<br>
    <textarea rows="7" name="f3" cols="30" style="width:50%;"></textarea></tr>
    <tr><td colspan="2" align="center"><input type="submit" 
    value="Отправить СООБЩЕНИЕ" onClick='location.href="ССЫЛКА НА СТОРОННИЙ РЕСУРС"'></td></tr>  
    JavaScript Holden Cortez, Sep 4, 2019

  • 1 Answers
  • 0
    <script type="text/javascript">
    $( "form" ).submit(function( event ) {
    var formData = new FormData();
    formData.append("f1", document.querySelector("input[name='f1']").value);
    formData.append("f2", document.querySelector("input[name='f2']").value);
    formData.append("f3", document.querySelector("textarea[name='f3']").value);
    var request = new XMLHttpRequest();
    request.open('POST', 'http://mydape.ru');
    request.onload = function()
    window.location.href="https://google.com"; // перенаправляем на гугль.

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!