0
Then, the code below (is complete in https://codepen.io/RaoniSousa/pen/Zpkxbb), the if works but this Else No, what is wrong?
I would like it to work like this one, in the "NAME" input by scrolling the bar (https://codepen.io/freeCodeCamp/pen/YqLyXB). When to fill the input the label appears and rises, when clean the input the label goes down and then disappears. I’m picking up js yet.
I thank anyone who can help.
var z = document.getElementById('name');//input com ID name
var x = document.getElementById('label');//label com ID label
z.addEventListener("keypress", function () {
'use strict';
if (typeof z.value !== "") {
x.style.opacity = '1';
x.style.bottom = '4em';
x.style.color = '#722872';
} else {
x.style.opacity = '0';
x.style.bottom = '1.5em';
}
seBlur();
seFocus();
});
but Else is a condition that only executes when if is false...ie if is true it executes the information of the if block, if not(Else) it executes the Else block
– MagicHat
@Magichat unless he said he never enters
else
:P– MarceloBoni
@Marceloboni will only not enter Else if it is true, otherwise you have to enter...
– MagicHat
So I thought: if there is character in input (if), x.style... otherwise (if empty input is (Else))...
– Raoni Batista de Sousa
The problem with the first link you sent is that in your if:
if (typeof z.value !== "") {...
, removes thetypeof
it’s already all right. And As in the answer below, keyup works better– Miguel