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();
}
);
Solved! Go to Solution.
Can you provide more details about the error you are getting? Does it point to a particular line in your app?
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 {
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.
Awesome! This worked on my end too! Thanks.