+ 2

Html forms

My problem is to make a form with two submit buttons. If you hit the first button, you will come to a website and if you hit the second button, you will come to an other website.

14th Mar 2019, 9:43 PM
M R
M R - avatar
10 Antworten
+ 1
first of all use onsubmit-function in a form it looks like: <form onsubmit="a(event);"> then you change your function to: function a(event){ event.preventDefault(); window.location.replace("https://www.google.com"); } Then it should work. You have to try this on your local machine because sololearn playground won't allow redirects
15th Mar 2019, 10:28 AM
S DK
S DK - avatar
+ 2
Yeah but how link to a website in Js?
14th Mar 2019, 10:45 PM
M R
M R - avatar
+ 2
Thanks
14th Mar 2019, 10:48 PM
M R
M R - avatar
+ 2
Call function and make an if Statement
14th Mar 2019, 11:30 PM
Alpha
Alpha - avatar
+ 2
https://code.sololearn.com/Wbwfvdpa3gPa/?ref=app The window.location.replace do not work here, do I have something wrong? 🤔
15th Mar 2019, 5:58 AM
M R
M R - avatar
+ 1
call the same function and make an if statement in the function on which button was clicked
14th Mar 2019, 10:03 PM
S DK
S DK - avatar
+ 1
window.location.replace(url)
14th Mar 2019, 10:47 PM
S DK
S DK - avatar
+ 1
no problem. feel free to ask again
14th Mar 2019, 10:48 PM
S DK
S DK - avatar