There is a form with input

<form method="post" action="bla.php" class="x_order_form" onsubmit="yaCounter38229915.reachGoal('order3'); return true;"> <input class="x_client_name" type="text" name="name" placeholder="Александр" required> <input class="x_client_phone" type="tel" name="phone" placeholder="+7 (___) ___-__-__" required> <button type="submit">Подтвердить</button> </form> 

I need to click on the button in the current window to open a new page, and in the new window there would be the result of the onsubmit of the form itself. Focus should go to a new window with the result of the form.

 <script type="text/javascript"> var forms = document.getElementsByTagName('form'); for (var i in forms) { forms[i].setAttribute('target', '_blank'); forms[i].onsubmit = function() { window.location.href = 'http://yandex.ru'; } } </script> 

This script opens the result of the form in a new window, but does not load the new url in the current one. Tell me what's wrong?

  • What do you want to see in the new window? this script does not fit here - L. Vadim
  • in the new window should be bla.php in which the form will make a post request - Artem Balan
  • I do not understand, in bla.php will be the result of the form, but in the new window what do you need? - L. Vadim
  • so in the new window it’s necessary to have the result of the form, I did this by adding the anchors [i] .setAttribute ('target', '_blank') attribute; to form. But I still need to, instead of the main page opened a new url - Artem Balan
  • ' site.com ' change this link to yours - L. Vadim

1 answer 1

The problem was that chromium does not handle lokoshin transitions in a cycle. Solved the problem by setting a timeout of 500. Now everything goes.

 <script type="text/javascript"> var anchors = document.getElementsByTagName('form'); for (var i=0; i< anchors.length; i++) { anchors[i].setAttribute('target', '_blank'); console.log("blank"); } var a = document.getElementsByTagName('form'); var nseelink = ('http://cnn.com'); for(var i in a) { a[i].onsubmit = function() { console.log('222222'); go(nseelink); } } function go(link){ setTimeout(function(){ window.location.href = link; },500) } </script>