-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainpage.js
More file actions
39 lines (34 loc) · 1013 Bytes
/
Copy pathmainpage.js
File metadata and controls
39 lines (34 loc) · 1013 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import React, { useState } from 'react';
const Dropdown = () => {
const [selectedOption, setSelectedOption] = useState('');
const handleChange = (event) => {
setSelectedOption(event.target.value);
// Send the selected choice to the backend server
fetch('/display_choice', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ choice: event.target.value }),
})
.then((response) => response.json())
.then((data) => {
console.log(data);
})
.catch((error) => {
console.error('Error:', error);
});
};
return (
<div>
<h1>Dropdown List Example</h1>
<select value={selectedOption} onChange={handleChange}>
<option value="">Select Option</option>
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
</select>
<p>Selected Option: {selectedOption}</p>
</div>
);
};
export default Dropdown;