How to change input box borders after filling the box using javascript ?

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

1. Code:

<!DOCTYPE html>
<body style="text-align: center;">
    <h2> Change input borders after filling data </h2>
        <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 != '') {
       = "3px dotted red";

2. Example:

Run the program to get the result.