Function that opens certain address by adding input value

0

I have an input and would like that when clicking on Search or enter open a certain address adding the value of the input: Example

<form align="center" method="GET">
    <input type="text" placeholder="Faça sua pergunta" autofocus name="query" size="50">
    <input  type="submit" onclick="myFunction()" value="Buscar">
</form>
    
    <script>
    function myFunction() {
        var query = document.getElementsByName('query'); 
        window.open("http://leituracrista.com/indice/?query=" + query.value);
        
        }
    </script>
    
asked by anonymous 16.04.2018 / 19:30

1 answer

1

I replied in your previous post ... try to use the target and method GET .

<form align="center" method="GET" target="_blank>


     <input type="text" placeholder="Faça sua pergunta" autofocus name="query" size="16" style="font-size: 11 pt; color: #000000; font-family: Verdana; font-variant: small-; border: 1 solid #000000">
     </font></font> <font face="Verdana, Arial, Helvetica, sans-serif" size="2"> 
     <input  type="submit" value="Buscar"  style="font-size: 8 pt; color: #000000; font-family: Verdana; font-variant: small-caps; border: 1 solid #000000">

</form>

If you want to know more about: link

What you want to do in this case is:

<script>
function myFunction() {
  var query = document.getElementsByName('query')[0];
  window.open("http://leituracrista.com/indice/?query=" + query.value);
}
</script>
    
16.04.2018 / 19:33