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.
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.
Semi-colon at the end of the if line?...
Here is the complete block:
function sendEmail(ev) {
on(dom.byId("btnFeedback"), "click", function () {
If(document.getElementById("eMail").value == null || document.getElementById("eMail").value == "") {
alert("not working");
} else {
sendEmail();
}
);
I removed the semi-colon but still receive a syntax error.
sendEmail takes one parameter, but you pass none inside the else block. Although, you never actually use 'ev', so you may as well remove it.
You may get better results by flipping it around (I suspect the problem is to do with "== null"):
If((document.getElementById("eMail").value) && document.getElementById("eMail").value != "")
Still getting a syntax error.
I have my code on github here if you want to see it: https://github.com/csergent45/streetSigns
I am working through two issues.
You said you have two issues. Is the other issue happening first? I've experienced situations where valid code broke due to an issue elsewhere in my code.
I am just trying to figure out a toggle layer visibility. I re-uploaded my project as I comment out what I am not working on so they don't conflict.
How about....
If( (document.getElementById("eMail").value == null) || (document.getElementById("eMail").value == "") ) {
You could also try '===' (three equal signs) instead of '=='
It's still an error with the extra )