I'm currently using Sublime and trying to link a dropdown menu with an input text using html, css, and javascript. When the user selects an option from the dropdown menu, I want the corresponding value to appear in the text input field. For example, if the user clicks on "italian" in the dropdown menu, the text input should display "italian".
Although I have written the code, it doesn't seem to be functioning as intended:
<!DOCTYPE html>
<html>
<head>
<style>
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
background-color: #3e8e41;
}
</style>
</head>
<title>Calculators</title>
<body bgcolor="yellow">
<h1 style="color:red;">Calculators:</h1><br>
<p style="margin-left: 50px;">
<a href="C:\Users\ALBINO\Desktop\prove\calculator\index.html" target="_self">Example Calculator</a><br>
<a href="index2.html" target="_self">Italian Calculators</a><br>
<a href="http://web2.0calc.com/">Online Scientific Calculator</a>
</p>
<div id="examplePicture" style="margin-left: 500px;">
<img src="http://i.ebayimg.com/00/$T2eC16NHJIkE9qU3jckhBRY0k-ob)!~~_35.JPG" />
</div>
<div class="dropdown">
<button onclick="myFunction() class="dropbtn" >Choose your favourite calculator</button>
<div id="myDropdown" class="dropdown-content">
<a href="#">italian</a>
<a href="#">german</a>
<a href="#">brazilian</a>
<a href="#">french</a>
<a href="#">spaniard</a>
</div>
</div>
<input type="text" id="display" disabled><br>
<script src="homeJava.js"></script>
</body>
</html>
Below is the javascript code I've implemented:
var textbox = document.getElementById('display');
function myFunction() {
textbox.value += document.getElementById("myDropdown").classList.();
}
If anyone could provide some assistance, it would be greatly appreciated.