I wrote following piece of code to retrieve value of ‘recipientList’ in array abc but it is not working. Whenever I use
alert(abc[i]);
It returns ‘undefined’.
I need to use this abc[i]’s value as ‘options[]’ index in
document.getElementById(“recipients”).options[i].selected
What am I doing wrong?
var abc;
<logic:greaterThan value="0" property="ConfigId" name="ConfigForm">
<%
ArrayList<RecipientDTO> recipientList= (ArrayList<RecipientDTO>) request.getAttribute("recipientTypesList");
if (recipientList != null && recipientList.size() > 0)
{
for (int i=0; i < recipientList.size(); i++)
{
RecipientDTO recipientType = (RecipientDTO) recipientList.get(i);%>
abc = [<%=recipientType.getRecipientType().toString()%>];
<% } %>
var i;
for(i=0;i<abc.length;i++) {
document.getElementById("recipients").options[i].selected = true;
}
<% }
%>
</logic:greaterThan>
I also used
var abc = new Array();
abc[i] = "<%=recipientType.getRecipientType().toString()%>";
instead of
var abc;
abc = [<%=recipientType.getRecipientType().toString()%>];
but no use 🙁
try replacing
var abcwithvar abc=new Array()andwith