Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

How to change the <input> type?

  • Difficulty Level : Hard
  • Last Updated : 18 Apr, 2021

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.


Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

  • 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
Recommended Articles
Page :