Skip to content
Related Articles
Open in App
Not now

Related Articles

How to change the <input> type?

Improve Article
Save Article
  • Difficulty Level : Hard
  • Last Updated : 18 Apr, 2021
Improve Article
Save Article

The purpose of this article is to change the HTML <input> type. Javascript provides document.getElementById().type option to change the type of input field.


  • The selected input type will change to text.
  • The selected input type will change to a button.
  • The selected input type will change to a date.



<!DOCTYPE html>
      Please click on Button2 to see the type 
      of Button1 change from button to text
      onclick="alert('I am Input1 click on Input2 to see me change my type')"/>
    function typeChanger() {
      alert("The type of Input1 will now change from button to text");
      document.getElementById("inputfield1").type = "text";


Input to text

Note: Some Old Browsers do not allow a dynamic change in the type of input fields.

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!