Javatpoint Logo
Javatpoint Logo

The Oninput Function in Javascript

The oninput function works on the text, selects, and inputs data by user tag on the html input tag. When you can input data, the function changes the functionality as per requirement using javascript. When input completes the inserting data or stops focusing on the input tag, JavaScript stops the functionality.

Javascript and html support the oninput functionality for the input, select, and textarea tag. This functionality depends on the user interface. We can add validations and user restrictions for better application operation. We can use it for text, passwords, and other user information.

Ways to Use the Function

There are three ways to use the Oninput function in javascript. We can use the function in three ways: only javascript, html with javascript, and javascript with addEventListener.

  • Oninput function in javascript
  • Oninput function in html with javascript
  • Oninput function in javascript with addEventListener

Oninput function in javascript

The function uses a selector with the oninput function directly in the javascript. The event validation uses in the function name using javascript.

Syntax

The following syntax uses in the web page to operate the oninput function.

Examples

The following examples show the operation and working procedure of the Oninput function in javascript.

Example 1:

In the example, we can use the html tag with the oninput event and function in the script tag. Here, the function uses to add validation for the interactive user field.

Output

The following image shows the oninput functions output information.

The Oninput Function in Javascript

Example 2:

In the example, we can use the html tag with the oninput event and function in the script tag. Here, the function uses to add validation for the textarea input field.

Output

The following image shows the oninput functions output information.

The Oninput Function in Javascript

Example 3:

In the example, we can use the oninput event and function in the script tag. The function works when we select the data using the dropdown field.

Output

The following image shows the oninput functions output information.

The Oninput Function in Javascript

Oninput function in html with javascript

The event uses the HTML input tag, such as input, select, and textarea. The function uses in the script tag or js page with the validation.

Syntax

The syntax uses the oninput function directly in the html tag with the function name.

Examples

The following examples show the operation and working procedure of the Oninput function in html with javascript.

Example 1:

In the example, we can use the oninput in html tag and the function used in the script tag. Here, the function uses to add validation for the interactive user fields.

Output

The following image shows the oninput functions output information

The Oninput Function in Javascript

Example 2:

In the example, we can use the oninput in the input html tag and the function used in the script tag. Here, the function uses to add validation for the password type of the interactive user field.

Output

The following image shows the oninput functions output information

The Oninput Function in Javascript

Example3:

The javascript function uses for the input range in this example. The oninput event works when the range selects in the html tag.

Output

The following image shows the oninput functions output information

The Oninput Function in Javascript

Oninput function in javascript with addEventListener

The function used in the addEventListener() method with the selector. The "input" keyword is necessary to operate the oninput function with the javascript function name.

Syntax

The following syntax shows an oninput event with the addEventListener () method.

Examples

The following examples show the operation and working procedure of the Oninput function in javascript with addEventListener.

Example 1:

In the example, we can use the html tag with the oninput event and function in the script tag. Here, the function uses to add validation for the interactive user field. The add event listener method with input keyword is essential for the event in the script tag.

Output

The following image shows the oninput functions output information

The Oninput Function in Javascript

Example 2:

In the example, we can use the html tag with the oninput event and function in the script tag. Here, the function uses to add validation for the interactive user fields. The add event listener method with input keyword is essential for the event in the script tag.

Output

The following image shows the oninput functions output information

The Oninput Function in Javascript

Conclusion

The oninput event is useful for user interaction and validation. It is mostly used for forms and user information.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA