我在动态表中有三个选择标签。您可以根据需要添加任意数量的行。第一个下拉列表包含数据库中产品列中的所有产品。第三个下拉列表获取在第一列的第一个下拉列表中选择的所有产品的价格。尽管出于某种原因,如果我从第一列的其他行中选择产品,则价格将添加到第三列的第一个下拉列表中,而不是它们各自的下拉列表中,但至少它获得了正确的价格。如何将下拉列表中的这些价格添加到数组中。例如:$dropdown = $_POST['price'] - 所有价格都将在下拉变量中,然后我可以使用 MultipleIterator() 来获取值。
$(document).ready(function(){
$.getJSON("getSolution.php", success = function (data){
var options = "";
for(var i = 0; i < data.length; i++){
options += "<option>" + data[i] + "</option>";
}
$(".meetingPlace").append(options);
$(".meetingPlace").change();
});
$('#quoteTable1').on('change','.meetingPlace',function () {
$.getJSON("getSolutionPrice.php?make=" + $(this).val(), success = function (data){
var options = "";
for(var i = 0; i < data.length; i++){
options += "<option>" + data[i] + "</option>";
}
//$(".costing").html("");
$(".costing").append(options);
});
})
});
<table class="table table-striped table-borderless table-header-bg test" id="quoteTable1">
<tr><span class="center-block text-center" style="font-weight: bold">Inital Fee</span>
<th class="text-center" style="width: 5%">D</th>
<th class="text-center" style="width: 50%">Description</th>
<th class="text-center" style="width: 15%">Units</th>
<th class="text-center" style="width: 35%">Cost</th>
</tr>
<tr>
<td class="text-center">
<input type="checkbox" name="chk[]">
</td>
<td>
<select class="js-select form-control meetingPlace" name="initial_solution[]" style="width: 100%;" data-placeholder="Choose one..">
</select>
</td>
<td class="hidden-xs">
<select class="js-select form-control" id="example-select2" name="initial_quantity[]" style="width: 100%;" data-placeholder="Choose one..">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</td>
<td>
<select class="js-select form-control costing" name="cost[]" style="width: 100%;" data-placeholder="Choose one..">
</select>
</td>
</tr>
</table>
<div class="form-group text-center">
<button class="btn btn-primary push-5-r push-10 plusbtn" type="button"><i class="fa fa-plus"></i> Add New Solution</button>
<button class="btn btn-danger push-5-r push-10 minusbtn" type="button"><i class="fa fa-times"></i> Delete Solution</button>
</div>
<script>
$(document).ready(function() {
$('.plusbtn').click(function() {
$(".test").append('<tr><td class="text-center"><input type="checkbox" name="chk[]"></td><td><select class="js-select form-control meetingPlace" name="initial_solution[]" style="width: 100%;" data-placeholder="Choose one.."><?php $query = "SELECT * FROM products"; $result = mysql_query($query, $connection); while($row=mysql_fetch_array($result)){ echo "<option>".$row["productName"]."</option>"; }?></select></td><td class="hidden-xs"><select class="js-select form-control" id="example-select2" name="initial_quantity[]" style="width: 100%;" data-placeholder="Choose one.."><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option></select></td><td><select class="js-select form-control" name="cost[]" style="width: 100%;" data-placeholder="Choose one.."></select></td></tr>');
});
$('.minusbtn').click(function() {
if ($(".test tr").length != 2) {
$(".test tr:last-child").remove();
} else {
alert("You cannot delete first row");
}
});
});
</script>
只是为了一个公平的想法,你可以使用以下:
HTML :
<select name="select_name" size="size in int" multiple="multiple">
PHP :
$data = $_POST['select_name'];
print_r($data);