将输入中的数据发送到custom.js,并根据custom.js文件中的输入进行计算,并从custom.js中将总和值发送到create.blade.js
create.blade.php
<div class="form-group col-md-4">
<label for="amount_received">Amount Received</label>
<input type="text" class="form-control" name="p_amount_received"
id="p_amount_received" oninput="myfunction()" placeholder="Enter Amount
Received" required="">
</div>
通过id获取在custom.js中接收的p_amount _
custom.js
function myFunction() {
var x = document.getElementById("p_amount.received").value;
var sum=x+10;
}
create.blade.php
<p></p>
我如何在
create.blade.php
中取回总和
答案 0 :(得分:0)
您可以使用标头中的脚本标签或create.blade.php中的类似内容加载custom.js,甚至可以使用onchange调用myFunction,
<input type="text" class="form-control" name="p_amount_received"
id="p_amount_received" onChange="myFunction()" placeholder="Enter Amount
Received" required="">
<label id='p_sum_display'>Sum</label>
<input type="hidden" name="p_sum" id="p_sum" >
创建sum作为输入以提交给服务器,并sum作为显示标签以进行ui显示,并通过myFunction之类的方法填充值,
function myFunction() {
var x = document.getElementById("p_amount_received").value;
var sum=x+10;
document.getElementById("p_sum").value = sum //for submit to server
document.getElementById("p_sum_display").innerHTML = sum // to display to user on ui
}