Skip to content Skip to sidebar Skip to footer

Html Form Action Search, One Text Box, 2 Buttons, 2 Possible Results

I am trying these days to do a search form that sends to two different pages with two different buttons with a single text box. So far I am doing this:
Copy

Solution 2:

Since you tried and failed a script, let's look at ways we can achieve this.

Using form

Be extremely wary of what you do here. It is easy to send a get request using form but it always "flushes" out the query strings already present in the action URL, and submits the request by adding name-value pairs in its child nodes. Make sure to create your query as a child node.

<inputtype="text"id="box"name="searchbox"maxlength="128"placeholder="Type text to be searched here"autofocus /><inputtype="button"value="Youtube"onclick="search_youtube()"/><inputtype="button"value="Torrentz"onclick="search_torrentz()"/><script>functionsearch_youtube(){
    var add="https://www.youtube.com/results";       
    var box = document.getElementById("box");
    box.name="search_query"if(box.value)
    {
        var form = open().document.createElement("form");
        form.action=add;
        form.appendChild(box.cloneNode(false))
        form.submit();
    }
   } 

  functionsearch_torrentz(){
    var add="https://www.torrentz.com/search";             
    var box = document.getElementById("box");
    box.name="q"if(box.value)
    {
        var form = open().document.createElement("form");
        form.action=add;
        form.appendChild(box.cloneNode(false))
        form.submit();
    }
  }
</script>

Using HTML5 formaction attribute

<form action="https://www.youtube.com/results" method="GET">
    <inputtype="text" id="box" name="search_query" maxlength="128" placeholder="Type text to be searched here" autofocus />
    <inputtype="submit" value="Torrentz" formaction="https://www.torrentz.com/search" onclick="document.getElementById('box').name='q'" />
    <inputtype="submit" name="submit" value="Youtube" />
</form>

Post a Comment for "Html Form Action Search, One Text Box, 2 Buttons, 2 Possible Results"