How to set the selected index of the drop-down list to 0 when changing the text of the text field?

I use the dropdown to populate the text box. But if there is no preferred value in the drop-down list, then the directirect user enters a value in this text box.

If the user first selects a value from the drop-down list, and then he does not want this value, and he types in another text in this text box, then at this time the drop-down menu should be set to index 0 when the user enters a different value.

I used the textchanged text event, but it does not work. Can someone tell me how to write javascript for this? Thanks in advance.

+4
source share
1 answer

This should work for you:

function ResetDropDown(id) { document.getElementById(id).selectedIndex = 0; } function ResetTextBox(id) { document.getElementById(id).value = ''; } <select id="MyDropDown" onchange="ResetTextBox('MyTextBox');"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> </select> <input id="MyTextBox" type="text" onkeypress="ResetDropDown('MyDropDown');"/> 
+10
source

All Articles