Reputation: 3773
I have my HTML code similar to the below code.
<form action="/action_page.php">
<label for="cars">Choose a car:</label>
<select id="cars" name="cars">
<option value="volvo">Volvo XC90</option>
<option value="saab">Saab 95</option>
<option value="mercedes">Mercedes SLK</option>
<option value="audi">Audi TT</option>
</select>
<h1> </h1>
<input type="submit" value="Submit">
</form>
Here in the same form, I need to display the selected value in the tag.
Could someone guide how I can display the selected value in the tag as user makes the selection from the dropdown? Thanks.
Upvotes: 0
Views: 171
Reputation: 2303
Please use below code.
<html>
<head>
<style>
</style>
</head>
<body>
<form action="/action_page.php">
<label for="cars">Choose a car:</label>
<select id="cars" name="cars" onchange="document.getElementById('tag').innerText=this.value;">
<option value="volvo">Volvo XC90</option>
<option value="saab">Saab 95</option>
<option value="mercedes">Mercedes SLK</option>
<option value="audi">Audi TT</option>
</select>
<h1 id="tag"> </h1>
<input type="submit" value="Submit">
</form>
</body>
</html>
Upvotes: 1