Lucas
Lucas

Reputation: 57

How to use attributes from request with javascript?

Why does the alert box not work?

<script>
<% Player player = (Player) request.getAttribute("player"); %>
alert(<%=player.getTempId()%>);
</script>

Upvotes: 1

Views: 39

Answers (1)

Michael Seltenreich
Michael Seltenreich

Reputation: 3488

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

Upvotes: 1

Related Questions