check empty input

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 is not working for me.

    
asked by anonymous 14.02.2017 / 09:19

1 answer

3

Give me an idea that you're using MooTools ... is that the case?

So, 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, .get('value') will give you a string and .trim() removes empty spaces, so if it is empty, only "" will be left over.

    
14.02.2017 / 09:34