What is wrong with my syntax in this conditional statement?

5477
14
Jump to solution
05-01-2015 11:13 AM
ChrisSergent
Regular Contributor III

I am trying to see if a field is empty, but I am receiving a syntax error. Any ideas:

on(dom.byId("btnFeedback"), "click", function () {

        If(document.getElementById("eMail").value == null || document.getElementById("eMail").value == ""); {

            alert("not working");

        } else {

         

        sendEmail();

       

    }

      

    );

Tags (2)
14 Replies
KellyHutchins
Esri Frequent Contributor

Can you provide more details about the error you are getting? Does it point to a particular line in your app?

ChrisSergent
Regular Contributor III

I can't believe I forgot to post the error message.

Just in case it helps, I'll add that to this thread as well:

ncaught SyntaxError: Unexpected token {

ChrisSmith7
Frequent Contributor

Try this:

on(dom.byId("btnFeedback"), "click", function (e) {

    if (document.getElementById("eMail") == null || document.getElementById("eMail").value == "") {

             alert("not working");

    } else {

            sendEmail();

        }

});

Hope this helps! I confirmed this is working on my end...

The way it sits now, whenever someone clicks on "btnFeedback", it will throw an alert window if the "eMail" element isn't on the page, or, it is, but the value is empty, otherwise, we'll send an e-mail.

I made some minor mods, including lowering the case on your initial "If" to "if". I removed the "value" method on your first condition... it shouldn't ever be null, just "". I left the check because if it's not on the page, it will throw the alert. getElementById should always return an object, even if it's not found... it'll be a null object. Additionally, I removed the ";" from your conditional and fixed your mismatched brackets.

curtvprice
MVP Esteemed Contributor
ChrisSergent
Regular Contributor III

Awesome! This worked on my end too! Thanks.

0 Kudos