还有 就是 当我在选定的destList里面用鼠标选取了某个选项后,在提交页面,destList就能传过去。 也就是说,我从srcList选道destList后,在destList用鼠标点上,提交的话就能传到serlet,请问能不能实现不用鼠标点上,也能把destList里所有的东西都传递过去

解决方案 »

  1.   

    <form action="">
      <table width="200">
        <tr>
          <td align="left" height="25" width="40%"><select multiple name="srcList" size=5>
              <option value="1">1</option>
              <option value="2">2</option>
              <option value="3">3</option>
              <option value="4">4</option>
            </select></td>
          <td align="center" height="25" width="20%"><br />
            <input type="button" name="Submit" value="&gt;"  onclick="moveSelected(this.form.srcList, this.form.destList)"/>
            <br />
            <input type="button" name="Submit2" value="&lt;" onclick="moveSelected( this.form.destList, this.form.srcList)"/>
          </td>
          <td align="left" height="25" width="40%"><select multiple name="destList" size=5   selected>
            </select>      </td>
        </tr>
      </table>
    </form>
    <SCRIPT LANGUAGE="JavaScript">
    <!--/**
     * move options from a select to another select
     * @param object targetSelect as html element select
     * @param object targetSelect as html element select
     * @version build 20051018
     * @author [email protected]
     */
    function moveSelected(sourceSelect, targetSelect){
    var cachOptionsArray = new Array();
    var index = 0;
    for (var i = sourceSelect.options.length - 1; i >= 0; i--){
    if (sourceSelect.options[i].selected){
    cachOptionsArray[index] = new Option(sourceSelect.options[i].text, sourceSelect.options[i].value);
    sourceSelect.options[i] = null;
    index++;
    }
    }
    var exist = false;
    for (var i = cachOptionsArray.length - 1; i >= 0; i--){
    exist = false;
    for (var j = 0; j < targetSelect.options.length; j++){
    if (targetSelect.options[j].value.toString() == cachOptionsArray[i].value.toString()){
    //alert("“" + cachOptionsArray[i].text + "”已经存在了!");
    //sourceSelect.options[sourceSelect.options.length] = cachOptionsArray[i];
    exist = true; 
    break;
    }
    }
    if (!exist){
    targetSelect.options[targetSelect.options.length] = cachOptionsArray[i];
    }
    }
    }
    //-->
    </SCRIPT>