1

我有一个文本框,允许用户在其中输入字母数字输入。我还有一个加号图像,单击时必须将输入的文本添加到名为“add key num”的多选框(如下所示)。在多选框“add key num”中添加几个输入后,用户可以单击左箭头将最终列表添加到“list key num”选择框中。我被困在将文本输入从文本框添加到第一个选择框的 JavaScript 上。请指教。样本图像

这是我拥有的代码:

<cfparam name="SESSION.stkeynum" default="">
<table border="1" align="center" STYLE="margin-left:120px;" bgcolor="##B0C4DE">         
<tr>
    <td align="center" >ENTER KEY NUM</td>
    <td align="center" ></td>
    <td align="center" >ADD KEY NUM</td>                
    <td align="center" ></td>
    <td align="center" >LIST KEY NUM</td>
    <td align="center" >AMOUNT</td>             
</tr> 
<tr>
    <td align="center"><input type="text" maxlength ="8" name="vstkeynum" id="vstkeynum" value="" size="15"></td>
    <td><img src="../images/plus.jpg" alt="Add Key number" onclick="add_cc(document.myform.vstkeynum.value);"></img></td>
    <td nowrap>
        <div id="Div1"></div>   
        <select name="keynumber" size="5" multiple style="width: 175px; display: inline;">
            <option value="null"> </option> 
        </select> 
    </td>
    <td><img src="../images/arrow_right.gif" alt="Add To List" onclick="copySelectedOptions_edit(document.myform.keynumber,document.myform.keynumber_selection);">
        <hr>
        <img onclick="removeSelectedOptions_edit(document.myform.keynumber_selection);" src="../images/arrow_left.gif" alt="Delete From List">  
    </td>
    <td nowrap>
        <select name="keynumber_selection" size="5" multiple style="width: 175px;">
        </select>
    </td>
    <td align="center"><input type="text" maxlength ="8" name="amount" id="amount" value="" size="7"></td>
</tr> 
</table> 

JavaScript:

<script type="text/javascript">
    function add_cc(a) {
    // inital load
    ajax({
        url: 'add_keynum.cfm?vval=' + a,
        fillDiv: 'Div1',
        showBusy: true
    });
    document.myform.vstkeynum.value = "";
    }
</script>
<script>
    function copySelectedOptions_edit(from, to) {
    var options = new Object();
    if (hasOptions(to)) {
        for (var i = 0; i < to.options.length; i++) {
        options[to.options[i].value] = to.options[i].text;
        }
    }
    if (!hasOptions(from)) {
        return;
    }
    for (var i = 0; i < from.options.length; i++) {
        var o = from.options[i];
        if (o.selected) {
        if (options[o.value] == null || options[o.value] == "undefined" || options[o.value] != o.text) {
            if (!hasOptions(to)) {
            var index = 0;
            } else {
            var index = to.options.length;
            }
            to.options[index] = new Option(o.text, o.value, false, false);
        }
        }
    }
    if ((arguments.length < 3) || (arguments[2] == true)) {
        sortSelect(to);
    }
    from.selectedIndex = -1;
    to.selectedIndex = -1;
    }

    function removeSelectedOptions_edit(from) {
    if (!hasOptions(from)) {
        return;
    }
    if (from.type == "select-one") {
        from.options[from.selectedIndex] = null;
    } else {
        for (var i = (from.options.length - 1); i >= 0; i--) {
        var o = from.options[i];
        if (o.selected) {
            from.options[i] = null;
        }
        }
    }
    from.selectedIndex = -1;
    }
</script>

这是 add_keynum.cfm 中的代码:

<cfif isDefined("vval")  >
    <cfif trim(vval) neq "">
        <cfset SESSION.stkeynum = Listappend(SESSION.stkeynum,vval)>
        <cfoutput>#SESSION.stkeynum#</cfoutput>
    <cfelse>
        <cfif isDefined("session.stkeynum")>
            <cfoutput>#SESSION.stkeynum#</cfoutput>
        </cfif>
    </cfif>
</cfif>
4

0 回答 0