1

Why does the alert box not work?

<script>
<% Player player = (Player) request.getAttribute("player"); %>
alert(<%=player.getTempId()%>);
</script>
2
  • 1
    Have you checked the browser console for errors? Commented Jan 4, 2016 at 17:44
  • have u try alert(player.getTempId()); ? Commented Jan 4, 2016 at 17:49

1 Answer 1

1

I'm guessing the function returns a string. try this:

alert("<%=player.getTempId()%>");

Because if a string is returned without quotes you'll get the page to render this:

alert(aString) //and then you'll get an error that aString is not defined. 

By adding "" the page will render like so:

alert("aString") //and will work
Sign up to request clarification or add additional context in comments.

Comments

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.