dongpao5261 2016-12-28 15:40
浏览 20
已采纳

没有被选中的选择框多个[重复]

This question already has an answer here:

I have two small select boxes like this:

enter image description here

I added a small JS-functionality and attached them to the buttons, so I can move my left items to the right box, which works just fine.

However, after transferring them to the right box (which in my case is the box with the elements I want to insert in the DB afterwards), they are selected. Clicking on one of them deselects the other one. I want to have both of these options (which are generated dynamically) to be in my PHP-file.

enter image description here

This looks fine so far, but on a closer look, it doesn't work... which makes sense, since only one item is selected. Instead of taking only the selected items, I want all items of the right box.

My JavaScript for the transfer is this:

function move(leftValue, rightValue) {
    var leftSelect = document.forms["myedit"].elements[leftValue];
    var rightSelect = document.forms["myedit"].elements[rightValue];
    if (leftSelect.selectedIndex == -1) {
        window.alert("[{oxmultilang ident='TROEXTENDEDNEWS_SELECT_LEFT_FIRST'}]");
    } else {
        var option = leftSelect.options[leftSelect.selectedIndex];
        rightSelect.appendChild(option);
    }
}

pretty short. move left index to right index.

This is my HTML (left box):

<select class="editinput" name="editval[cats_available][]" multiple>                          
    <option value="abc">abc</option>
    <option value="def">def</option>
</selected>

This here is how I submit the form:

<input type="submit" name="save_new_cat" value="[{ oxmultilang ident='TROEXTENDEDNEWS_CREATE_NEW'}]" onClick="selectAllOptions('editval[cats_selected][]');document.myedit.fnc.value='createCategory'">

My question: What would be a good approach to have items in the post-request which are in the right box? Maybe before submitting the code a small JS-function which selects all items in the right box? Using a hidden field after clicking on the "move right" button? I'm kinda stuck here.

No jQuery available.

</div>
  • 写回答

1条回答 默认 最新

  • dongxun6690 2016-12-28 15:44
    关注

    Have you tried the solutions on select all options in html select dynamically yet, because your issue seems similar to the question over there?

    Please have this answer moderated to a comment, because it is one.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题