How to access link with parameter via form in html or html5?

2

I have the following code in html.

<form action="http://www.meulinkqueseraredirecionado.com/namer/">
      <input type="text" />
      <input type="submit" value="Acessar" />
</form>

I want as soon as the user clicks the "Access" button, after inserting a number in the "text" input, he / she accesses the link "

How is HTML or HTML5 done?

    
asked by anonymous 05.12.2015 / 21:38

1 answer

2

Using just JavaScript, you can do this:

document.getElementById('enviar').addEventListener('click', function(e) {
  var param = document.getElementById('param');
  var act = document.getElementById('form');
  act.action += param.value;
  window.open(act.action, '_blank');
  act.action = "http://www.meusite.com/";
});
<form action="http://www.meusite.com/" id="form">
  <input type="text" id="param">
  <input type="submit" id="enviar">
</form>

By clicking the submit button, JavaScript will take the value of the parameter field and add it to the value of the action attribute of the form.

Note: In the StackOverflow snippet the form submit is blocked.

    
05.12.2015 / 22:02