0

I’m using this form to do the search

<form name="formchercher" method="post" target="_blank">
Recherche : <input id="keyword" type="text" name="rechercher">  <input type="button" value="go!" onclick="return search()">
</form>

When I click the button, it calls this function :

function search() {
    //var keyword = document.forms["myform"]["fname"].value;

    document.forms["formchercher"].action="http://www.biaugerme.com/index.php"
    document.forms["formchercher"].submit();

    document.forms["formchercher"].action="http://www.germinance.com/index.php"
    document.forms["formchercher"].submit();

    document.forms["formchercher"].action="http://www.grainesdelpais.com/"
    document.forms["formchercher"].submit();

    document.getElementById("keyword").name = "recherche";
    document.forms["formchercher"].action="http://www.magellan-bio.fr/recherche.html"
    document.forms["formchercher"].submit();

    document.getElementById("keyword").name = "q";
    document.forms["formchercher"].action="http://www.semencesdupuy.com/fr/catalogsearch/result/"
    document.forms["formchercher"].method="get";
    document.forms["formchercher"].submit();

    document.getElementById("keyword").name = "search_query";
    document.forms["formchercher"].action="http://www.semaille.com/fr/recherche"
    document.forms["formchercher"].submit();
}

I’m changing the action of the form for each website and then submitting the form again.

The issue with this code is that it only opens one tab and shows the result from the last website.

It’s working for each individual website. If I comment everything in the function but one website, it shows the result from this website correctly in a new tab.

How do I get this code to open 6 different tabs and return a result from each of these sites?

Albizia
  • 517
  • 8
  • 18

1 Answers1

2

The key here, is that browser blocks all your submission except the last. Using setTimeout is one way of preventing this to happen, but the timeout should long enough for one submission to be done, before the next one can happen. Otherwise, the browser blocks the rest. In this case, you might be able to submit for example 3 of them, but not the rest. Below code, I tested and opens all 6 websites you've listed in your question.

   <form name="formchercher" target="_blank" method="post" onsubmit="search()">
        Recherche : <input id="keyword" type="text" name="rechercher">  <input type="submit" value="go!" >
   </form>

-

function search() {
    setTimeout(function(){ 
        document.forms["formchercher"].action="http://www.biaugerme.com/index.php"
        document.forms["formchercher"].submit();
    }, 1000);

    setTimeout(function(){ 
        document.forms["formchercher"].action="http://www.germinance.com/index.php"
        document.forms["formchercher"].submit();
    }, 2000);

    setTimeout(function(){ 
        document.forms["formchercher"].action="http://www.grainesdelpais.com/"
        document.forms["formchercher"].submit();
    }, 3000);

        setTimeout(function(){ 
        document.getElementById("keyword").name = "recherche";
        document.forms["formchercher"].action="http://www.magellan-bio.fr/recherche.html"
        document.forms["formchercher"].submit();
    }, 4000);

    setTimeout(function(){ 
        document.getElementById("keyword").name = "q";
        document.forms["formchercher"].action="http://www.semencesdupuy.com/fr/catalogsearch/result/"
        document.forms["formchercher"].method="get";
        document.forms["formchercher"].submit();
    }, 5000);

    setTimeout(function(){ 
        document.getElementById("keyword").name = "search_query";
        document.forms["formchercher"].action="http://www.semaille.com/fr/recherche"
        document.forms["formchercher"].submit();
    }, 6000);
}

Another solution is mentioned in this post Submit two forms with one button (check the second answer). I believe you can have ajax calls, and upon success of one, you can call the next one, and so on and so forth.

Community
  • 1
  • 1
Armin
  • 220
  • 2
  • 10