pick input value and redirect page after submit

1

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

Ex:

site.com/busca/ BUY VALUE

<form>
<input type="text"/>
<input type="submit" value="Pesquisar"/>
</form>
    
asked by anonymous 06.08.2016 / 05:28

1 answer

1

You can get the value by id and use 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>
    
06.08.2016 / 07:26