I have a text box and 2 radio buttons in my ASP.Net Core MVC web page as shown below:
If the "Existing" radio button is clicked, the text box should change to a dropdown list. And if the "New" radio button is clicked, the dropdown list should be changed to the textbox. Since I am very new the web technology, I don’t know how to do it. please help.
.table1 {
display: inline-block
}
<div class="table1">
<label> Level 3 Num</label>
<input type="text" name="text1" class="l3n" placeholder="Level 3 Num" maxlength="100" style="margin:5px;width:400px; height:30px;border:1px solid #01579B;" />
<label>
<input type="radio" name="editList" value="new" />New
</label>
<label>
<input type="radio" name="editList" value="existing" />Existing
</label>
</div>
3
Answers
So first you need to add an ‘id’ to your input so it looks like this:
and then create a Select tag with id="existing" tag and a display of ‘none’ that will hold your existing options.
Once you’ve done that you just need a event handler :
}
You can use the following code as suggested by @Yogi using datalist. You also need to use an event listener for each radio button. I used conditional ternary operator (same as if statement) to remove or keep the list attribute on the input box. You just need to add the code to read your input value
Here is a version based on Mehdi’s code, but using delegation and setting initial list based on default checked