Hayaz
Hayaz

Reputation: 119

Changing URL on select

I have created a group of options with the value and a button using react.

<select> 
<option value="https://hosters.pk/clientarea/index.php/store/flash-high-speed/basic-1?=1&billingcycle=monthly"> option1 </option>
<option value="https://hosters.pk/clientarea/index.php/store/flash-high-speed/unlimited?=1&billingcycle=quarterly"> option2 </option> 
</select> 
<button> Buy Now </button>

now what I want is. I want that when I select an option and click on the button It should change the URL as by given in its value. can you tell me how can I do that in React?

Upvotes: 0

Views: 833

Answers (1)

abhi patil
abhi patil

Reputation: 514

Just need to get the value from onSelect event. there are number of ways to do it 1] from window object = window.location.href =whatever the url 2] using the react-router or react-router-dom , which is the preferred way

<select onChange={(e)=>{window.location.href(e.value)}}> 
<option value="https://hosters.pk/clientarea/index.php/store/flash-high-speed/basic-1?=1&billingcycle=monthly> option1 </option>
<option value="https://hosters.pk/clientarea/index.php/store/flash-high-speed/unlimited?=1&billingcycle=quarterly"> option2 </option> 
</select> 

Upvotes: 1

Related Questions