donglv6960 2010-03-29 20:08
浏览 25
已采纳

如何使这些输入相互关联?

I have a series of checkbox inputs and corresponding text area inputs to allow specification of quantity.

Here's what the two fields look like when the item is static (i.e. only 1):

<input type="checkbox" name="measure[checked][]" value="<?=$item->id?>">
<input type="hidden" name="measure[quantity][]" value="1" />

Here's what the input fields look like for all items that have a specifiable quantity:

<input type="checkbox" name="measure[checked][]" value="<?=$item->id?>"> 
<input class="item_mult" value="0" type="text" name="measure[quantity][]" />

This would play nicely, if within the array, it didn't output like this, after collecting it with:

$field = $this->input->post('measure',true);

Array ( 

     [quantity] => Array ( [0] => 1 [1] => 1 [2] => 1 [3] => 1 [4] => 1 [5] => 1 [6] => 25 [7] => 0 [8] => 0 [9] => 0 [10] => 1 [11] => 1 [12] => 1 [13] => 1 [14] => 1 [15] => 1 [16] => 1 [17] => 1 [18] => 1 [19] => 1 [20] => 1 [21] => 1 [22] => 0 [23] => 0 [24] => 0 [25] => 0 [26] => 0 [27] => 0 [28] => 0 [29] => 0 [30] => 0 [31] => 0 [32] => 0 [33] => 0 [34] => 0 [35] => 0 [36] => 0 [37] => 0 [38] => 0 [39] => 0 [40] => 0 [41] => 1 [42] => 1 [43] => 1 [44] => 1 [45] => 1 [46] => 1 [47] => 1 [48] => 1 [49] => 1 [50] => 1 [51] => 1 [52] => 0 [53] => 0 [54] => 0 ) 

     [checked] => Array ( [0] => 4 [1] => 6 [2] => 13 ) 

) 

I understand what the values in the checked array are, I just do not understand how to relate the first field to the second, later in the program.

How do I incorporate the correct code to relate checked items to quantities?

  • 写回答

1条回答 默认 最新

  • doupeng8494 2010-03-29 20:30
    关注

    Use something common (the item id) to relate them:

    <input type="checkbox" name="measure[checked][<?=$item->id?>]" value="1"> 
    <input class="item_mult" value="0" type="text" name="measure[quantity][<?=$item->id?>]" />
    

    Now you'll know what measures relate to what items. However, a better way would be:

    <input type="checkbox" name="measure[<?=$item->id?>][checked]" value="1"> 
    <input class="item_mult" value="0" type="text" name="measure[<?=$item->id?>][quantity]" />
    

    Here you have an array (measure) of items, with two 'properties': 'checked' and 'quantity'. Easy to iterate over and understand.

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

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料