I have a variable defined at the top of my jsp page:
<%! int count = 0; %>
I then call jquery with a buttonclick like so:
<script type="text/javascript">
$(document).ready(function() {
$('#somebutton').click(function() {
var c = '<%=count%>';
<% count += 5; %>
});
});
</script>
The idea is that the variable count will be updated (and persist) after the function is done. However, it seems to update count locally but doesn't persist globally. When I click the button count always gets set to 5 but never increments to 10, 15, etc. upon further button clicks.
How can I update the jsp variable from within the jquery function and have it persist?