Context: I'm trying to create a simply project (a decision tree) and I'd like to know how could I create a drop down menu so that the user can select a specific option and retrieve a output from a json file.
This is the HTML code:
decisiontree.create(
window.location.href.replace(/\/.*\.html$/, 'coronary.json'),
document.getElementById('output'),
document.getElementById('status')
);
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<title>Decision Tree</title>
<script src="https://cdn.jsdelivr.net/npm/html-decision-tree/dist/decisiontree.js"></script>
<link rel="stylesheet" href="../styles/tree.css">
<link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@400;600&display=swap" rel="stylesheet">
</head>
<body>
<div class="content">
<header>
<h1> Knowledge-Based Decision Tree </h1>
</header>
<main class="main-content">
<div id="status">
<select id="selection">
<option value="coronary.json"> Hypertension Decision Tree </option>
<option value="diabetes.json"> Diabetes Decision Tree </option>
</select>
</div>
<div id="output"></div>
</main>
</div>
</body>
</html>
As you can see, I'm only allowing the user to access the 'coronary.json' file, but I'd like to allow the user to have some flexibility and select from a range of options from a dropdown menu. How could I make it so that the user selects an option and is then passed on the window.location.href.replace...
to use the information of a given file?
I believe I'd have to create some kind of querySelector
to retrieve the values of each option and then pass this values onto the window.location.href, but I'm not sure how I could do that
Thank you in advance!