0

My action specifies, let's say, an email address:

private String email;
public String getEmail() {
  return email;
}

But sometimes, the action can just not fill in the email, keeping it null. How can I evaluate this scenario in jquery?
Something like this definitely did not help:

<script type="text/javascript">
  $(document).ready(function() {
    if (${email}) {
      //do something
    } else {
      //do another thing
    }
</script>
3
  • 2
    You need to quote strings in JavaScript. Commented Jan 10, 2013 at 17:12
  • @DaveNewton thanks for the tip. GriffeyDog's answer did it. Commented Jan 10, 2013 at 17:13
  • 1
    Just a side note - adding quotes is all you need to do for this to work as the empty string will evaluate as false. Commented Jan 10, 2013 at 17:15

2 Answers 2

1

Javascript:

var myVar = "${email}";
if (myVar !== "") {
} else {
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can check the variable with typeof https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/typeof

1 Comment

In this case, I cannot. When the email is null, the javascript on the client would be generated like if (typeof()) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.