Skip to content
Advertisement

How to use and different options with element to redirect to an external website

I am trying to implement a list of options using <form> and <select>. Researching on the web, I notice that this is used to redirect to sections of the same website, but I want to make it work so that the user display the options and when they click on submit it redirects them to an external website.

JavaScript

Can I include inside some element like <option>"onChange method to_redirect='www.google.com'"</option> or what other way could make the website redirect users?

Advertisement

Answer

Navigating outside your application has nothing to do with react-router.

  1. Store the selection in a state variable
  2. On submit, use window.location to navigate to the chosen option
JavaScript

Edit white-https-50m320

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement