Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  2] [ 1]  / answers: 1 / hits: 48224  / 9 Years ago, sat, september 26, 2015, 12:00:00

Is it possible to run javascript functions inside jsp tags?
I'd like to run a sudden function as many times as there's objects in my ArrayList. Below doesen't work, but I hope it gives an idea of what I'm trying to achieve.



    <script>
function test(){
alert();
}
</scripts>


<%
ArrayList<Marker> list = new ArrayList<Marker>();

list = (ArrayList<Marker>)request.getAttribute(markers);

for(int i = 0; i < list.size(); i++){
%>
<script>
<%
test();
%>
</script>
<%
}
%>


Is it possible to do it with something like ?



<c:forEach var=name items=${markers}>
<%-- call my javascript function --%>

</c:forEach>

More From » jsp

 Answers
7

Below correction in your code will work fine for you



<script>
function test(){
alert(Hello); // added sample text
}
</script>


<%
ArrayList<Marker> list = new ArrayList<Marker>();

list = (ArrayList<Marker>)request.getAttribute(markers);

for(int i = 0; i < list.size(); i++){
%>
<script>
test(); //No need to put java script code inside scriptlet
</script>
<%
}
%>

[#64923] Wednesday, September 23, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
collinisaaka

Total Points: 194
Total Questions: 105
Total Answers: 104

Location: Tonga
Member since Tue, Nov 30, 2021
3 Years ago
;