Last Updated : Jul 24, 2023
OnChange event also used for changing the elements of Html.It easily detecting a user’s response. onchange event is generally useful for validation, detecting user’s input etc.
- Firstly, we use <html> tag it is the beginning of Html document.
- <head> tag defines the head section of html document.
- <body> tag defines the content of html document.
- <h1> tag in code used for define the heading text in html
- Next we use select element with id as a “language” . It is a dropdown list that the users have an options to language selecting.
- We have use three option element in this code. Option has a value include languages- Hindi, English, Sanskrit. Then we close the select tag
- Now, the <div> method in this code will display the selecting language.
- In this code, we can use changelanguage() function to give the value of this language.
- After that we can define a variable inside the function named language.In this variable we can use getElementById() method to accessing the select element by its id attribute and update the value of property of selected option.
- Then, we can define another variable inside the function named res. It uses getElementById() to assigning a reference to res variable.
- Next, will displaying the text “selected language:” concatenate with the selected language that we selected.
We can use select element to dropdown the menu and we can also use different- different option where user can select any one option in these. For example- options include hindi, English, Sanskrit.
User can select any one option in these included option.We can use changelanguage() function when the user selects a language, changelanguage() function is called.