Hi
 
 I have attached Pasted the code which solves your problem.
 
    Logic: On Click of the button, call a javascript function.
              In the function,
                    Iterate through the select box and find out if the values are selected. If selected added it to a variable.    
                    In this way construct a comma seperated values (CSV) of values selected in the select box.
 
               Now pass this comma separated value to the servlet where you can get back the values by StringTokenizing with comma as the delimiter.
 
            For your Information: Javascript does not support string array. So you have to use a CSV values only. You can change the delimiters to #, $ etc., whichever you feel convenient.
_______________________________________________________________________________________________
<script language="javascript">
     function listValue(){
        valInSelect = "";
        len = document.Sort.selectTest.options.length;
      
        for (i = 0;i < len; i++) {
            if ( document.Sort.selectTest.options[i].selected) {
                valInSelect = valInSelect + "," +
                              document.Sort.selectTest.options[i].value;
            }
        }
        alert ("The Val In Select is" +  valInSelect);
 
    }
</script>
 
 <form name="Sort">
    <select name="selectTest" size=2 width=200 multiple>
        <option value="Servlet">Servlet
        <option value="JSP">JSP
        <option value="J2EE">J2EE
    </select>
 
     <input type="button" name="Add" value="ADD"
     >       
 
 </form>
___________________________________________________________________________________________________________________
 
 
Thanks & Regards
Balasubramaniyan Krithivasan

 
I have a text box for putting a value, a "add" button for adding this value to the list (multiple select),
and a "remove" button for removing value(s) from the list.  I guess the question is how do
I convert the content of this list to an array so I can pass it to the servlet...or...I am not sure if
using a multiple select is a right choice.  The only reason I use a multiple select list is so
I can remove more than one value from the list after adding values incorrectly.
I can make it work only if the values in multiple select list are selected (...of course).  Do you
know a way to make the values in the list "selected" by default?  Thanks:)

Reply via email to