Reputation: 13415
For example I've got model attribute curPage
on my jsp page.
How to change its value in javascript function?
Something like this
function prev() {
var curPage = '${curPage}'; //get value
if (curPage > 1)
curPage--; //modify it
'${curPage}' = curPage;
}
Upvotes: 1
Views: 3035
Reputation: 415
JavaScript is executed on the client side, while the model attributes exist on your server.
In case of your example above, the ${curPage}
will be replaced with the value of $curPage at runtime and the javascript would be sent to your client. Any modifications you make to the curPage variable will stay on the client side.
If you want to persist this change to your server, you need to make some kind of web request back to the server(ajax, form submit etc.)
Upvotes: 1