button with link inside the form

Asked

Viewed 1,020 times

2

Guys I got a form with 2 button within. 1 and Ubmit and the other need to put a link in it. When clicked it cannot send the form and call the link.

Follows my code:

<form name='form' method=post action='link' enctype='multipart/form-data'>

   <button type='submit'>

   <button> link

<form>
  • 1

    Place a javascript event on the button, which changes the value of window.href to the address you want to go to. Remember this will not cause a post.

1 answer

3


Within a <form> buttons without type defenido behave as type="submit". Then you need to have type="button".

To make it redirect to another page you can inline like this:

<form name='form' method=post action='link' enctype='multipart/form-data'>
   <button type='submit'>Enviar</button>
   <button type="button" onclick="window.location='http://google.com'">link</button>
</form>

or with an event headphone like this:

var btn = document.querySelector('button[type="button"]');
btn.addEventListener('click', function(){
    window.location='http://google.com';
});

Having in HTML only:

<button type="button">link</button>
  • 1

    Very good, solved my problem here ;)

Browser other questions tagged

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