Function that opens a given address by adding input value

Asked

Viewed 21 times

0

I have an input and would like to click Search or enter to open a certain address by adding the input value: 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>

1 answer

1


I responded in your previous post... try using the target and the 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: https://www.w3schools.com/tags/att_form_target.asp

what you want to do in case is:

<script>
function myFunction() {
  var query = document.getElementsByName('query')[0];
  window.open("http://leituracrista.com/indice/?query=" + query.value);
}
</script>
  • Sylviot does not serve, because this way every search opens a new window, what I want is to be able to share this form so that it can be inserted in any site you want, without the need to share the whole html file, but only the search button, understand? but anyway thanks for the reply

  • Does it solve? var query = document.getElementsByName('query')[0]; window.open("http://leituracrista.com/indice/?query=" + query.value);

  • testing and I’ll get back to you

  • Perfect, thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.