check empty input

Asked

Viewed 143 times

2

I have an input text and want to check if the value is empty. In my example I have this:

var qttDeclared = tr.getElement("input[name$='[qttDeclared]']").get("value").toInt()
if(qttDeclared == "") {
        console.log("vazio");
    }

But this isn’t working for me.

1 answer

3


Give me the idea that you’re using Mootools... that’s the case?

Anyway, with this API you can do it like this:

var qttDeclared = tr.getElement("input[name$='[qttDeclared]']").get("value").trim();
if(qttDeclared === "") {
    console.log("vazio");
}

That is, the .get('value') will give you a string and the .trim() removes empty spaces, so that if it is empty it will remain only "".

  • I noticed that there is a negative vote in my reply. A comment is welcome, I do not mind if there are things to improve the answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.