3
我有兩個選擇框一個選擇框是多選擇選項,有一個添加更多按鈕添加多個行相同的選擇框,值以數組格式傳遞,我想打印每一行多個選擇選項。多選擇選項
------------------------------------------------------------------
Select1 | Select2 | Textbox
------------------------------------------------------------------
Option1 Option1
Option2 Option2
Option3 Option3
Option4 Option4
我選擇在第一選擇框和第二選擇框中的多個選項中選擇第一選項(選項1和選項2),在第二行i選擇在第一選擇框和第二選擇框中的多個選項中選擇(選項3和3選項第二選項)。 我點擊提交按鈕,我想打印
Option1 Option1
Option1 Option2
Option2 Option3
Option2 Option4
但現在打印(需要從多個選擇中的所有數據)
Option1 Option1
Option1 Option2
Option1 Option3
Option1 Option4
Option2 Option1
Option2 Option2
Option2 Option3
Option2 Option4
這裏是我的代碼:
<div id="lobrows">
<div class="form-group">
<div class="col-sm-4"><label>Reson</label>
<select class="form-control selectpicker" data-live-search="true" name="reson[]" required="required">
<option>--Select--</option>
<option value="1">List 1</option>
<option value="2">List 2</option>
<option value="3">List 3</option>
<option value="4">List 4</option>
</select>
</div>
<div class="col-sm-4"><label>Service </label>
<select class="form-control selectpicker" data-live-search="true" name="service[]" id="service" multiple="multiple">
<option>--Select--</option>
<option value="1">List 1</option>
<option value="2">List 2</option>
<option value="3">List 3</option>
<option value="4">List 4</option>
</select>
</div>
<div class="col-sm-4"><label>Name </label>
<input type="text" class="form-control" name="name[]" placeholder="Name" />
</div>
</div>
</div>
<a href="#" class="pull-right" id="add"><i class="fa fa-plus"></i> add</a>
<script type="text/javascript">
$(document).ready(function() {
$('#add').click(function(e) {
e.preventDefault();
var i=$('.mrbtm').length+1;
$('#lobrows').append('<div class="mrbtm"><div class="form-group"><div class="col-sm-4"><label>Reson </label><select class="form-control selectpicker" data-live-search="true" name="reson[]"><option>--Select--</option><option value="1">List 1</option>
<option value="2">List 2</option>
<option value="3">List 3</option>
<option value="4">List 4</option></select></div><div class="col-sm-4"><label>Service </label><select class="form-control selectpicker" data-live-search="true" name="service[]" id="service'+i+'" multiple="multiple"><option>--Select--</option><option value="1">List 1</option><option value="2">List 2</option><option value="3">List 3</option><option value="4">List 4</option></select></div><div class="col-sm-4"><label>Name </label><input type="text" class="form-control" name="name[]" placeholder="Name" required="required" /></div></div><a href="#" class="pull-right remove"><i class="fa fa-minus"></i> Remove</a><br /></div>');
$('.selectpicker').selectpicker();
$('.selectpicker').selectpicker('refresh');
});
$(document).on('click', '.remove', function(e) {
e.preventDefault();
$(this).parent('div').remove();
i--;
});
});
</script>
這是我的PHP代碼:
<?php
foreach ($reson as $id => $value) {
$reson = ($reson[$id]);
$namep = ($name[$id]);
foreach ($service as $ii => $valu) {
$r_service = ($service[$ii]);
echo "Option".$reson."----"."Option".$r_service ."<br>";
}
}
?>