gpt4 book ai didi

javascript - 从 Bootstrap 模式获取值,处理然后将值插入数据库

转载 作者:行者123 更新时间:2023-12-01 01:42:50 25 4
gpt4 key购买 nike

我正在使用从数据库打印值的表。然后我做出选择。之后,我想将这些值与 Bootstrap 模式中需要填充的值一起处理。一旦获得所有值,我需要将它们存储到数据库中。

表存储数据库中的值:

<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

在这些值下方,我有提交按钮,该按钮可打开 Bootstrap 模式。

<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>

一旦我点击“发送请求”,它就会打开 Bootstrap 模式:

<!-- 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">&times;</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>

我想从 Bootstrap 模式和所选值所在的 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>

我正在寻求建议?非常感谢任何形式的帮助。

最佳答案

您的模态在几个级别上未正确编码。

首先,input元素没有 id分配的。通常情况下,人们可以通过 id 获取该值。 。与您在这里所做的类似:

 var x = document.getElementById("quantity").value;

此外,虽然它与从模式中读取值无关,但从 Bootstrap 的 Angular 来看,您的输入表单并未按照 Bootstrap CSS 期望的方式进行编码。

这里是 Bootstrap 的示例站点:

 <div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
</div>

注意每个输入都包含在 form-group 中。如果您使用此布局,则无需使用 <br>标签。

关于javascript - 从 Bootstrap 模式获取值,处理然后将值插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34512342/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com