【发布时间】:2015-12-29 13:43:26
【问题描述】:
我正在使用从数据库打印值的表。然后我做出选择。之后,我想将这些值与需要填充的引导模式中的值一起处理。获得所有值后,我需要将它们存储到数据库中。
数据库中的表存储值:
<table id="table" class="table table-bordered table-striped">
<thead>
<tr class="bg-red">
<th>Id</th>
<th>Material</th>
<th>Quality</th>
<th>Dimensions</th>
<th>Colors</th>
<th>Weight</th>
<th><center><i class="fa fa-shopping-cart"><center></th>
</tr>
</thead>
<tbody>
<?php while($r=$q->fetch()){ ?>
<tr>
<td class='data-id'><?='B-'. $r['Id']?> </td>
<td> <?=$r['Material']?> </td>
<td><?=$r['Quality']?></td>
<td><?=$r['Dimensions']?></td>
<td><?=$r['Colors']?></td>
<td><?=$r['Weight']?></td>
<td> <button class="addValues" name="code[]" value="<?='B-'. $r['Id']?>"><i class="fa fa-shopping-cart"></button></td>
</tr>
<?php } ?>
</tbody>
</table>
然后我使用脚本进行行选择并将值打印到另一个 div(这部分有效)
<script>
$(".addValues").click(function () {
$('#selection').show();
var $this = $(this),
myCol = $this.closest("td"),
myRow = myCol.closest("tr"),
targetArea = $("#selection");
var qte_input = (' <input type="text" name="quantity[]" placeholder="kg / m" size="10"/>');
targetArea.prepend($("td.data-id", myRow).text() + qte_input +"<hr />");
});
</script>
选中行后在div中输出(可以多选)
B-15897 3000kg // B-15897 提供代码 3000kg 提供数量。 B-4589 500m
在这些值下方我有提交按钮,它会打开引导模式。
<div class="col-xs-2">
<div class="box box-danger">
<h4>Selected: </h4><br/>
<div id="selection">
<!-- SELECTED VALUES -->
B-15897 3000kg
B-4589 500m
</div>
<button class="btn btn-block bg-red btn-sm" data-toggle="modal" data-target="#myModal">Send request</button>
</div>
</div>
一旦我点击发送请求,它就会打开引导模式:
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" href="repromaterijali-script.php">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Offer request</h4>
</div>
<div class="modal-body">
* Company name
<input type"text" class="form-control" name="company" required><br/>
* Contact info
<input type"text" class="form-control" name="contact" required><br/>
* Adress
<input type"text" class="form-control" name="address" required><br/>
* Phone
<input type"text" class="form-control" name="tel"required><br/>
E-mail
<input type"text" class="form-control" name="email" ><br/>
Other
<textarea type"text" class="form-control" name="other" ></textarea><br/>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" name="submit">Send</button>
</div>
</div>
</div>
</div>
我想从引导模式和所选值所在的 div 中选择所有值,处理它们并通过 php 插入数据库中。代码和数量将是一个数组,因为可以选择多个值。
Bootstrap modal 和 div,其中选定的值在 <form> 内。我试图通过使用下面的脚本来获取值,但没有任何反应:
<script type="text/javascript">
function get_values() {
var x = document.getElementById("quantity").value;
var y = document.getElementById("code").value;
var arr = {barcode:x};
$.ajax({ url: 'insert.php',
data: arr,
type: 'post',
success: function(output) {
document.getElementById("code").value = output;
}
});
}
</script>
我正在寻求建议?非常感谢任何形式的帮助。
【问题讨论】:
-
您是否在调试器中单步执行您的代码以查看发生了什么?问题是从模式中获取值还是将值写入数据库?如果问题是更新数据库,你可以硬编码值来测试它正在工作的 PHP 吗?
-
从模态而不是数据库中获取值是问题,一旦我从模态中获取它们并创建变量,然后我会将它们插入到数据库中
标签: javascript jquery twitter-bootstrap