Tuesday, May 28, 2024
 Popular · Latest · Hot · Upcoming
18
rated 0 times [  19] [ 1]  / answers: 1 / hits: 21799  / 12 Years ago, thu, june 28, 2012, 12:00:00

There is a JSP page in which i have an ArrayList variable. I need these arraylist values(txt1 and txt2) in script tag.I have tried lots of combinations and googling but didnot succeed.



javascript function



function fun1()
{
// how to get arraylist values
}


JSP page:



 <body>
<%
ArrayList<String> al= new ArrayList<String>();
al.add(txt1);
al.add(txt2);

out.println(<input type=text id= + al.get(0) + >);out.println(<br>);
out.println(<input type=text id= + al.get(1) + >);out.println(<br>);
out.println(<input type=button id=btn1 value=click onClick=fun1(); > );
%>
</body>


Thanks for reply


More From » java

 Answers
9

Inside javascript you can use Scriplets very well



Assume the list 'arrayList' is having [1,2,3,4] in java (JSP)



you can get the array list by this



function fun1()
{
var list = '<%= arrayList %>';
}


if you print the variable list, it will be a string with value '[1,2,3,4]'



You can then split this using Regex or simple string operation



<body>
<%
ArrayList<String> al= new ArrayList<String>();
al.add(txt1);
al.add(txt2);

out.println(<input type=text id= + al.get(0) + >);out.println(<br>);
out.println(<input type=text id= + al.get(1) + >);out.println(<br>);
out.println(<input type=button id=btn1 value=click onClick=fun1(); > );
%>
</body>

<script>
// try the script here
</script>

[#84605] Wednesday, June 27, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
americar

Total Points: 631
Total Questions: 107
Total Answers: 103

Location: Luxembourg
Member since Tue, Jan 25, 2022
2 Years ago
;