This isn't exactly a struts question, but I've seen some similar questions
posed in this user list related to java script. What I'm trying to do is
display values in a drop down list based on a value selected from another
drop down. Depending upon what is selected, I will get the value selected
from the drop down, and dynamically populate the second drop down. I am
using the onchange java script attribute on my struts html tag that fires
an event when I select an item from the first drop down. I need to take the
value selected, use it as a key, and get data from a preloaded array that
has the data that I need for the second drop down. I know from reading
through the struts user list that I need to load the array in the java
script function to be able to get data from from it. The question is, how
do I load this array in my java script function?

Can the allMethodsTypes array get loaded in the java script function by
referencing it as a JSP expression?

Thanks,
Jane

Here's the code

<%

     String [][] allMethodsTypes;

          try {
               allMethodsTypes  = new String [methodNamesList.size()][];
               for (int methodindex = 0; methodindex < methodNamesList.size
(); methodindex++) {
                    String method
= (String)methodNamesList.get(methodindex);
                    methTypes = bomb.getListOfMthdTypeDef(method);
                    allMethodsTypes[methodindex] = new
String[methTypes.size() + 1];
                    allMethodsTypes[methodindex][0] = new String(method);
                    for (int typeindex = 0; typeindex < methTypes.size();
typeindex++) {
                         String type = (String)methTypes.get(typeindex);
                         allMethodsTypes[methodindex][typeindex + 1] = new
String(type);
                    }
               }
          }
          catch (Exception e) {
               System.out.println("Exception building allMethodsTypes
array" + e);
             }
     }
%>

<select name="methodNames" size="1" onchange="selectMethodTypes(this.form)"
>

<script language="JavaScript1.1">
     function selectMethodTypes(f, test)
     {
     var i;
     var x;
     if(!f) {
         return;
     }

     var l = f.methodNames.length;
     for (i=0; i<f.methodNames.length; i++) {
        if (f.methodNames[i].selected) {
          var s = f.methodNames[i].value;
          alert(s);
          <%
          for (x=0; x<allMethodsTypes[i][].length; x++) {
          %>
              if (s = allMethodsTypes[i][x]);
               f.methodTypes[x].value = allMethodsTypes[i][x];
              }
          }
        }
     }
     }
</script>



****************************************
This email message and all attachments transmitted with it are for the sole use of the 
intended recipient(s) and may contain confidential and
privileged information. Please DO NOT forward this email outside of the recipient's 
Company unless expressly authorized to do so herein.  Any
unauthorized review, use, disclosure or distribution is prohibited. If you are not the 
intended recipient, please contact the sender by reply email
and destroy all copies of the original message.

Any views expressed in this email message are those of the individual sender except 
where the sender specifically states them to be the views of Indus
 International, Inc.
****************************************


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to