Reputation: 175
I want to use scriplets inside a javascript function. And inside the scriplet i want to make use of a javascript variable. How can i access javascript variable inside the scriplets?
code:
<script>
window.onload = function(e)
{
arr = $('#hidden_field').val();
arr = JSON.parse(arr);
for(var i=0;i < arr.length;i++){
<% SomeClass class = doSomething(arr[i]);
%>
}
}
</script>
I want to pass the arr[i] value to the doSomething function and get some result. How can i do this?
Upvotes: 0
Views: 130
Reputation: 555
Why you want to access modal to view directly as per good exercide it's not right to do this.Because you should send your data through response. but if you want to do this then follow below:
you can do one thing assign your JS variable value to any hidden field then access it.
<input type="hidden" name="test" value="10">
onSubmit form below script will execute -
<%
length=request.getParameter("test);
for(int i=0;i<Integer.parseInt(length);i++){
SomeClass class = doSomething(arr[i]);
}
%>
Upvotes: 1