ConditionRacer
ConditionRacer

Reputation: 4498

Change visibility of a control in JSP based on bool value

I'm guessing I will need to use javascript to do this, but I'm completely clueless. I've never used javascript before. Can someone give me a quick sample of how to change the visibility of a button based on a bool value in a JSP page?

Upvotes: 1

Views: 1026

Answers (2)

ConditionRacer
ConditionRacer

Reputation: 4498

Here was my final solution:

<c:if test="${viewModel.facebookToken != ''}">
  <script type="text/javascript">
    var e = document.getElementById("facebookButton");
    e.style.display = 'none';
  </script>
</c:if>

Upvotes: 1

Murat Sutunc
Murat Sutunc

Reputation: 953

If you are thinking about using it only once it's easy to include JSP value in your JS code:

  <script type="text/javascript">
           var e = document.getElementById("foo");
            var myvar='<%=myScriptletVar %>'
            if (myvar)
                e.style.display = 'none'; 
    </script>

Upvotes: 3

Related Questions