tags:

views:

45

answers:

2

hi, this is my code

<html:select property="singleSelect">
<html:option value="0">Select One </html:option> 
<script type="text/javascript">
var nfhEvents =new Array();
<% ArrayList nfhList = simple.Reject();
String[] stringArray = (String[])nfhList.toArray(new String[nfhList.size()]);
System.out.println("Size   "+stringArray.length);%>
var state = new Array(<%= stringArray %> );
for (int i = 0; (i < <%= stringArray.length%>); i++) {
    document.write("<option value='"+state[i]+"'>" + <%= stringArray[i]%>+"test" +"</option>");
}
</script>
   this is not working fine. how to print values one by one in the option. pls help asap
<html:select>
A: 

Use JSP's taglib JSTL. You can then use <c:forEach> tag to display all options. Try to avoid scriptlets.

Padmarag
my manager asked me to use scriplets.pls help asap..
Manu
reformat the above code..if its having any mistake..
Manu
+2  A: 

Here is an example of what I did with the calendar month (in javascript)

<select name="birthMonth"><option value="-1">-&nbsp;Month:&nbsp;-</option>
    <script type="text/javascript">
    var monthStr = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November","December");

        for (var i = 0; i < 12; i++) {
            if (i != 8) {                                           
              document.write('<option value="' + (i + 1) + '">' + monthStr[i] + '</option>');
        } else {
              document.write('<option value="' + (i + 1) + '" selected>' + monthStr[i] + '</option>');
        }
       }
    </script>
</select>

I hope this helps you.

EDIT: Since you're using Struts

<html:select property="singleSelect">
<html:option value="0">Select One </html:option> 
<% ArrayList nfhList = simple.Reject();
String[] stringArray = (String[])nfhList.toArray(new String[nfhList.size()]);
//You MUST do this
request.setAttribute("stringArray", stringArray);
%>
<logic:iterate id="s" name="stringArray">
  <html:option value="${s}"><bean:write name="s" /></html:option>
</logic:iterate>
</html:select>
The Elite Gentleman
And you can please your manager with scriptlets....lol
The Elite Gentleman
dipalying error like below..Cannot find bean: "stringArray" in any scope
Manu
ok....check my edit....
The Elite Gentleman
thanx dude its working fine..thanks 4 ur effort
Manu
Cool, if it works, then vote this answer as it can help those with same issues *grin* :)
The Elite Gentleman