jwright9
asked on
Passing an array into a JSP from a struts action.
I am passing an array of string values from my database into a jsp via a form bean. The array of string values were retrieved and and loaded into the form bean in a Struts action.. However, when I do this:
<input id='ValueList' type='hidden' value='<%=valueList%>' />
The array is not getting assigned correctly to the hidden input variable correctly.
These javascript lines are not working well:
var answer = [];
answer = document.getElementById('V alueList') .value;
alert('MY VALUE LIST:::::' + answer[0]);
Is there a way to do this that actually works?
<input id='ValueList' type='hidden' value='<%=valueList%>' />
The array is not getting assigned correctly to the hidden input variable correctly.
These javascript lines are not working well:
var answer = [];
answer = document.getElementById('V
alert('MY VALUE LIST:::::' + answer[0]);
Is there a way to do this that actually works?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
dxdinh has a good point. Try using
<input id='ValueList' type='hidden' value='${valueList[0]}' />
<input id='ValueList' type='hidden' value='${valueList[0]}' />
As per i know thats not possible bcz your array list have more than beans values so you cant take that values in java script .
do one thing just print this value
<input id="ValueList" type="text" value="<%=valueList%>" />
you will get result like this
@and something
do one thing just print this value
<input id="ValueList" type="text" value="<%=valueList%>" />
you will get result like this
@and something
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
so you can put that values like this
<%
List a=(ArrayList) request.getAttribute("valu eList");
Formbean fb;
for (int i=0; i<a.size;i++)
{
fb=(Formbean) a.get(i);
%>
<input type="hidden" id="hidd<%=i%>" name="hidd" value="<%=fb.getName()%>">
<%}%>
in java script
var answer = document.formname.hidd.val ue; //// u can get all values
thats all
<%
List a=(ArrayList) request.getAttribute("valu
Formbean fb;
for (int i=0; i<a.size;i++)
{
fb=(Formbean) a.get(i);
%>
<input type="hidden" id="hidd<%=i%>" name="hidd" value="<%=fb.getName()%>">
<%}%>
in java script
var answer = document.formname.hidd.val
thats all
I m glad it works for you and thanks for the points -
Really your getting answer with that solution.....
your selecting you cant get the values without casting .......................
your selecting you cant get the values without casting .......................
ASKER
dravidnsr has made a correct point. He left alot of useful examples. I would like to give him 200 points. I did give the other responder the initial points. I really do appreciate their effort. This is better than a text book since I got great help on a problem I encountered in practice.
I don't know Struts but that can't work. The expression <%= %> is for accessing scripting variables on the page. I think you should try
<input id='ValueList' type='hidden' value='${valueList}' />
or
<input id='ValueList' type='hidden' value='<%=session.getAttri
or maybe
<input id='ValueList' type='hidden' value='<%=request.getAttri