M
M
Maxim K2021-04-10 21:48:46
JavaScript
Maxim K, 2021-04-10 21:48:46

How to change the background of a textbox depending on the empty text in it?

Hello. There is a form on boostrap,

<div class="col-md-6">
                <div class="form-group">
                  <label for="form_name">Метка</label>
                  <input id="val1" type="text" name="val1" class="form-control" placeholder="Метка:" style="background-color: #ADD8E6;">
                </div>
              </div>


If there is no text, then the background is white, if there is at least one character, then the background color is any other - how can tacos be implemented ??? Maybe there is already a site with implemented ?? It’s just that for now I understand that it is necessary to take the meaning of the text, but then it’s still wild.

Found something like this:

var ta= /*получаем ссылку на textarea */;

if(!ta.value.trim()) {
// ta empty
} else {

}


But the idea has not yet been developed (((
THANK YOU.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Yarkov, 2021-04-10
@mkvmaks

input:placeholder-shown {
    border: 1px solid red;
}

Unless of course there is a placeholder

R
Rerurk, 2021-04-10
@Rerurk

If the state of the input (onchange) changes, look at the length of the entered text, if 0 change the background

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question