Write an HTML page that contains a selection box with a list of 5 countries. When the user selects a country; its capital should be printed next in the list. Add CSS to customize the properties of the font of the capital (color, bold and font size).
<!DOCTYPE html>
<html>
<head>
<title>Country Capitals</title>
<style>
#capital {
color: blue;
font-weight: bold;
font-size: 20px;
}
</style>
</head>
<body>
<h1>Select a Country</h1>
<select id="countrySelect" onchange="showCapital()">
<option value="">-- Select a Country --</option>
<option value="USA">United States</option>
<option value="INDIA">BHARATHA</option>
<option value="France">France</option>
<option value="Germany">Germany</option>
<option value="Australia">Australia</option>
</select>
<p>Capital: <span id="capital"></span></p>
<script>
function showCapital() {
// Get the selected country from the select element
var selectElement = document.getElementById("countrySelect");
var selectedCountry = selectElement.options[selectElement.selectedIndex].value;
// Set the capital based on the selected country
var capitalElement = document.getElementById("capital");
switch (selectedCountry) {
case "USA":
capitalElement.innerText = "Washington, D.C.";
break;
case "INDIA":
capitalElement.innerText = "Newdelhi";
break;
case "France":
capitalElement.innerText = "Paris";
break;
case "Germany":
capitalElement.innerText = "Berlin";
break;
case "Australia":
capitalElement.innerText = "Canberra";
break;
default:
capitalElement.innerText = "";
break;
}
}
</script>
</body>
</html>
With Css
<!DOCTYPE html>
<html>
<head>
<title>Country Capitals</title>
<style>
#capital {
color: blue;
font-weight: bold;
font-size: 20px;
}
</style>
</head>
<body>
<h1>Select a Country</h1>
<select id="countrySelect" onchange="showCapital()">
<option value="">-- Select a Country --</option>
<option value="USA">United States</option>
<option value="INDIA">BHARATHA</option>
<option value="France">France</option>
<option value="Germany">Germany</option>
<option value="Australia">Australia</option>
</select>
<p>Capital: <span id="capital"></span></p>
<script>
function showCapital() {
// Get the selected country from the select element
var selectElement = document.getElementById("countrySelect");
var selectedCountry = selectElement.options[selectElement.selectedIndex].value;
// Set the capital based on the selected country
var capitalElement = document.getElementById("capital");
switch (selectedCountry) {
case "USA":
capitalElement.innerText = "Washington, D.C.";
break;
case "INDIA":
capitalElement.innerText = "Newdelhi";
break;
case "France":
capitalElement.innerText = "Paris";
break;
case "Germany":
capitalElement.innerText = "Berlin";
break;
case "Australia":
capitalElement.innerText = "Canberra";
break;
default:
capitalElement.innerText = "";
break;
}
}
</script>
</body>
</html>
Save the code in an HTML file, and you can open it in a web browser to see your biodata webpage. Remember to include your photo file (e.g., your_photo.jpg) in the same directory as the HTML file or provide the correct file path in the src attribute of the img tag.