take input value and redirect page after Submit

Asked

Viewed 2,107 times

1

How can I get the value of an input and after "Submit" redirect to another page with this value in the url?

Ex:

site.com/search/VALOR_BUSCA

<form>
<input type="text"/>
<input type="submit" value="Pesquisar"/>
</form>

1 answer

3

You can take the amount by id and uses location.href

<form>
<input type="text" id="valor_busca"/>
<input type="submit" value="Pesquisar" onclick="redireciona()"/>
</form>
<script>
function redireciona(){
    var valor_busca = document.getElementById("valor_busca").value;
    location.href="site.com/busca/"+valor_busca;

}
</script>

Browser other questions tagged

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