In my webpage, I have multiple elements with unique IDs that all contain textboxes and labels as attributes.
Element 0
- Textbox
- Textbox
- Label
Element 1
- Textbox
- Textbox
- Label
Element 2
- Textbox
- Textbox
- Label
I want to show an error message when a user types in any of the textboxes. To do this, I've added an onkeydown JavaScript function to each attribute like so:
MyTextbox.Attributes.Add("onkeydown", "javascript:OnChangeData();");
This is my JavaScript function:
<script type="text/javascript">
function OnChangeData() {
var info = document.getElementById('<%= infoControl.ClientID%>');
infoDonneePersonnelle.textContent = "Error!";
}
</script>
Although everything seems to be working fine, there's an issue: When I type in a textbox of element 1 (which has ID 1), the error message appears in the last element with ID 5 instead of the first one where I typed.
In summary, I have 6 elements displayed with attributes. Whenever I type in a textbox of element 1, the error message is displayed in the last element regardless of where I actually made the input. How can I ensure that the error message is shown in the correct element based on its ID?