Simple Selection Panel

Looking to include a simple dropdown menu with 5 choices. Once a selection is made, an answer corresponding to that choice will appear in another field next to it. For example:

Choosing France from the dropdown would display 'Paris' in the adjacent field box.

I am working with HTML and CSS but could use some assistance since I'm not very proficient in coding. Thank you!

Answer №1

Take a look at this. To change the text in the second field, Javascript needs to be utilized. I provided options for three choices, but adding the remaining two should not be difficult.

Keep in mind that countryInput.value returns the "name" of an option, not the text displayed. For further clarification on how the Javascript functions, there are other resources available besides stackoverflow.

function cityChange() {
  var countryInput = document.getElementById("country");
  var cityInput = document.getElementById("city");
  var city = "";
  
  switch (countryInput.value) {
    case "france":
      city = "Paris";
      break;
    case "slovakia":
      city = "Bratislava";
      break;
    case "germany":
      city = "Berlin";
      break;
  }
  
  cityInput.value = city;
  
}
<select id="country" onchange="cityChange()">
  <option disabled selected> -- select a country -- </option>
  <option value="france">France</option>
  <option value="slovakia">Slovakia</option>
  <option value="germany">Germany</option>
</select>
<input type="text" id="city" readonly/>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I'm trying to understand why this code isn't running properly. Can someone explain why my CSS is not being executed?

For some reason, using button .order{} to select elements inside the button is not applying the CSS codes as expected. The text color remains unchanged. However, when using just `.order` to select the elements, the CSS code works perfectly fine. Can someon ...

Looking for a way to track the number of visits your website receives using Splunk?

Examples I've attempted: "url" | stats count index="indexname" "url" |stats count Is it necessary to establish logging on my webpage before I can access the hit count? ...

Why does my element appear to be a different color than expected?

I've developed a sleek wind map (check out for reference). Using a weighted interpolation every 10ms, I generate uVector and vVector data to calculate wind speed. Based on this speed, each point is assigned a specific color as outlined below. if (we ...

What is the best way to create a sliding motion to the right for a menu item, accompanied by a line when it

Is there a way to align the line to the right of the text when it's not selected, and have a new line appear on the left side that pushes the text and removes the line on the right side? Here is the design I'm trying to emulate. If you click t ...

Matching start and end of CSS selectors using regex

If I have elements with a title attribute like the examples below, how can I select the div with the title custom-marker-wqs-tailrace bbu-l2 using a CSS regex selector? <div title="custom-marker-awlr-tailrace bbu-l2"></div> <div ti ...

What is the method for defining the href attribute using the parameter passed through ejs?

For my node.js express application, I am utilizing ejs as the view engine. One of the pages in this application is a profile page that displays a user's information. Within this page, there is an anchor tag with the user's email address as the va ...

Update the numerical data within a td element using jQuery

Is there a way to use jquery to increase numerical values in a <td> element? I've attempted the following method without success. My goal is to update the value of the td cell by clicking a button with the ID "#increaseNum". Here is the HTML st ...

What is the reason behind the improved performance I experience in Chrome with the Developer Console open?

Currently, I am developing a small canvas game completely from scratch using pure JavaScript. This game utilizes a 2D lighting algorithm that is akin to the one found here. It features only one light source and 25 polygons, resulting in approximately 30,0 ...

"Learn an effective method for presenting JSON variable data in a Bootstrap modal with a clean design using three distinct columns

I have successfully loaded JSON data into my HTML page using JQuery. By clicking a button, I can trigger a bootstrap modal that displays the content of the JSON variable. However, there is an issue with how the JSON data is displayed. I need the data to b ...

Implementing a Standardized Template for Consistent Design and styling Throughout Website

As I work on building my website, I find myself struggling with some of the intricacies. The homepage is set up with a navbar and header, along with several pages that can be easily navigated to. While everything seems to be functioning properly, upon ins ...

What is the strategy to load a div exclusively when triggered by a click event, instead of loading it

Can anyone assist me with a problem I am facing on my scripting page? I am currently working on a website that showcases properties. I would like to know how to prevent a specific div from loading when the page initially loads, and instead have its content ...

Customizing external elements with React's inline styling feature

Trying to use React to style elements generated by a third-party library has been a challenge. In the snippet below, I was able to achieve the desired styling using CSS, but now I am looking to accomplish the same using JavaScript. This way, users can defi ...

Using Python and Selenium to interact with HTML tags within a table

Here is a table structure that I am working with:- <table> <tbody> <tr class="stripe"> <td colspan="3"/> </tr> <tr> <td style="width: 160px;">Field1:</td> <td style="wi ...

Utilizing Python Selenium to Interact with Buttons

Encountering an issue while trying to use Selenium to click on a tab or button within my web application. Below are the code snippet and CSS selectors: Error message: selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: #t ...

Could someone please clarify why the data I input is not appearing in my hbs file?

I've been facing an issue where I am unable to send data from my main.js file to bookings.hbs file, although it works perfectly fine when sending the same data to index.hbs file. Can someone help me identify where the error might be occurring? App.js ...

Display the HTML content retrieved from the SailsJS Controller

Exploring the world of SailsJS, I am on a mission to save HTML content in a database, retrieve it, and display it as rendered HTML. To achieve this goal, I have set up a sails model and a controller. This is what my model looks like: attributes: { ht ...

Tips on keeping a div element in a fixed position until triggered by jQuery

I've managed to create a navigation bar within a header that sticks to the top of the screen once you scroll down past 100px. The functionality works well, but I'm looking to make the navigation bar stay fixed on the right until it snaps, essenti ...

How to Correctly Align Links in Bootstrap Navbar

I am currently utilizing Bootstrap 5 and I am looking to perfectly center some links within the navigation bar. <header> <nav class="navbar navbar-expand-lg py-5"> <div class="container"> ...

When attempting to read text from an HTML file, JTextPane fails to include a newline character in the output

I am currently working on a project that involves extracting text from an HTML file based on the element's id and displaying it in a JTextPane. However, I am facing an issue where the displayed text does not go to a new line. Here is a snippet of the ...

Struggling with aligning and floating links to the right while crafting a custom navigation bar

I'm in the process of crafting a custom navigation bar for my website, with the intention of having my name prominently displayed on the far left while the links float to the far right. I've utilized CSS to style everything within the nav section ...