Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

cannot proceed to the desired path in select/option menu

I have a select menu in my code. It has two options. By clicking on each option, I want to proceed to another page on the same site. Here is my code:

import React, { useState, useEffect } from 'react'
import { useNavigate } from 'react-router-dom'

const navigate = useNavigate()

<div className="flex justify-center">
                    <select className="form-select form-select-sm aria-label=".form-select-sm example">
                    <option value="1" onChange={() => navigate('/')}>one</option>
                    <option value="2" onChange={() => navigate('/ext')}>two</option>
                    </select>
                </div>

but when I select each option, it doesn’t proceed to desired path. What’s wrong?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try using onClick event instead of onChange, onChange should be used on a select element and not on an option element. So either wrap the options in a select and use onChange or try using the onClick on the options.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading