- #1
mathmari
Gold Member
MHB
- 5,049
- 7
Hey!
I have created a dropdown menu as follows:
When we select for example Option1 I won't that something specific (that corresponds to that option) appears on the page. How do we do that? Do we have to do an if-loop oder do we write that in an other js file?
Do we maybe use something like:
Or do we create then a new link that contains the content that must be shown?
I have created a dropdown menu as follows:
JavaScript:
import { Select, MenuItem, FormControl, InputLabel } from '@material-ui/core';
import React, { useState } from 'react';
function DDMenu() {
const [selected, setSelected] = useState('');
const selectionChangeHandler = (event) => {
setSelected(event.target.value);
};
return (
<FormControl style={{ marginTop: 50, marginLeft: 100, width: 250 }}>
<InputLabel>Select one of the following options</InputLabel>
<Select value={selected} onChange={selectionChangeHandler}>
<MenuItem value={1}>Option1</MenuItem>
<MenuItem value={2}>Option2</MenuItem>
<MenuItem value={3}>Option3</MenuItem>
<MenuItem value={4}>Option4</MenuItem>
</Select>
</FormControl>
);
}
export default DDMenu;
When we select for example Option1 I won't that something specific (that corresponds to that option) appears on the page. How do we do that? Do we have to do an if-loop oder do we write that in an other js file?
Do we maybe use something like:
JavaScript:
switch(value) {
case "1": return <h1>One</h1> ;
case "2": return <h1>Two</h1>;
case "3": return <h1>Three</h1>;
case "4": return <h1>Four</h1>;
}
Or do we create then a new link that contains the content that must be shown?
Last edited: