form text to be added as a link

1

I would like to know How to set the link through a form ex: I have a field to fill, whatever is filled in this field and you open it in the link if 1234 is filled in, the link must be www.example.com/1234, if 12424 is filled in the link that has to be opened must be www.example.com.br/12424

    
asked by anonymous 14.05.2018 / 21:02

2 answers

1

You can use jquery to do this, I did run but I believe it will work:

You put this script in your index.php or create a .js file (do not forget to remove the <script> and </script> tag for it) and reference its index also works.

<script>
$(document).ready(function () {
  $("#botao").click(function () {
    var pegalink = document.getElementById('link').value;
      window.open("teste2.php/" + pegalink);
        });
 });
</script>

And add this to your index.php :

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><inputtype="text" name="link" id="link">
<input type="button" id="botao" name="botao">

And then just change the link from window.open to the page that wants to assign the values in the URL ( enviado.php , for example) and my values that are in the fields of the script and the inputs by their that works normal .

    
14.05.2018 / 21:40
1

Concatenate the value of the entry with the variable Url.

    $(function () {
        $('#button').on('click', function () {
            var text = $('#text');
            var Url='www.exemplo.com.br/';
            text.val(Url + text.val() );  
            //para funcionar corretamente add http:// aqui ou na var URL
            window.open("http://"+text.val());  
        });
    });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputtype="text" value="" id="text" style="width: 250px;" />
    
<button type="button" id="button" name="button">Enviar</button>
    
14.05.2018 / 22:29