Create an imput field and generate a link based on what the person put in the [closed]

-3

Hello, I need to create something like a form that has 2 fields. First name: Last name:

and a "send" button

What I need is that when the send button is clicked, go to a specific website www.XXXXXX.com/"firstname "

but without references to the name of the fields

I give an example because I do not know if it was understood

I have Field1 Name: Carlos Campo2 Surname: Garcia

"Send" button

When pressing, you should generate a link that is "www.XXXXXX.com/CarlosGarcia"

Thanks

    
asked by Leandro 30.05.2018 в 22:23
source

2 answers

1

Following the example of Lee Chevarria

You have to put the following code on the script tag:

/// #form es el id de tu formulario

    $("#form").submit(function( event ) {  
      event.preventDefault(); //   cancela el envió del formulario  
      var nombre = $(".nombre").val(); // obtienes el valor del input del formulario con la clase nombre 
      var apellido = $(".apellido").val();  // obtienes el valor del input del formulario con la clase apellido 
      var url = "http://www.XXXXXX.com/"+nombre+apellido;   
      location.href = url  // redireccion a la url que necesitas  
    });

All this using JQUERY .

    
answered by 30.05.2018 в 22:58
0

Something like that I think it can be ...

$("#form").submit(function( event ) {
    var nombre = $(".nombre").val();
    var apellido = $(".apellido").val();
    var url = "www.XXXXXX.com/"+nombre+apellido; 
    $(location).attr('href',url);
});

you could vary the way you call the function ... according to your form ...

    
answered by 30.05.2018 в 22:30