Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to change Input box borders after filling the box using JavaScript ?

  • Difficulty Level : Medium
  • Last Updated : 29 Jul, 2020

In this article, we will change the input border after filling the text on the input text field. The onchange event attribute works when the value of the element changes and select the new value from the list.

Approach: Whenever the input value is changed with some value by the user, the onchange event attribute is triggered. After the event is fired, the value is checked if it is not null. If the user value exists, then the bottom border of the input control is changed to dotted red color by using inline styling.


<element onchange = "script">

Example: In this example, we will change the border bottom style when the user type some text in the field.

<!DOCTYPE html>
<body style="text-align: center;">
        How to Change Input 
        borders after filling?
        <label> NAME</label>
        <input type="text" id="fname" 
                name="fname" value="">
        <input type="submit" value="submit">
        var gfg = document.getElementById("fname");
        gfg.onchange = function (e) {
            if (gfg.value != '') {
                        = "4px dotted red";


  • Before filling the text:
  • After filling the text:

Supported Browsers:

  • Google Chrome
  • Internet Explorer
  • Opera
  • Safari
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!