将表单输入值设置为模仿另一个输入值

huangapple go评论55阅读模式
英文:

Set form Input Value to mimic another input value

问题

I see that you want to set the value of "Amount Tendered" to mimic the value of "Amount Payable" in your PHP code. To achieve this, you can use JavaScript to copy the value from one input field to another. Here's how you can modify your code to do that:

// Add this JavaScript code to your existing script
$(document).ready(function () {
    // Function to copy the Amount Payable to Amount Tendered
    function copyAmountPayableToTendered() {
        var amountPayable = parseFloat($('[name="total_amount"]').val().replace(/,/g, ''));
        $('#tendered').val(amountPayable.toFixed(2));
    }

    // Call the function initially
    copyAmountPayableToTendered();

    // Add an event listener to recopy the value when Amount Payable changes
    $('[name="total_amount"]').on('input', function () {
        copyAmountPayableToTendered();
    });
});

This code will initially copy the value from "Amount Payable" to "Amount Tendered" when the page loads, and it will update "Amount Tendered" whenever the value of "Amount Payable" changes.

Make sure to include this JavaScript code within a <script> tag in your HTML document, preferably just before the closing </body> tag. Also, ensure that jQuery is included and properly configured on your page for this code to work.

英文:

I have a small program for selling coffee. after the order is placed, the total amount is shown as Amount Payable.

Thereafter they have to input how much they paying as Amount Tendered

I am trying to get the amount tendered input value to mimic the Amount Payable so it always puts the same amount.

Eg Amount Payable - 20
must auto be copied to
Amount Tendered - 20

My code is below:

&lt;?php include &#39;../db_connect.php&#39; ?&gt;
&lt;style&gt;
span.float-right.summary_icon {
font-size: 3rem;
position: absolute;
right: 1rem;
top: 0;
}
.bg-gradient-primary{
background: rgb(119,172,233);
background: linear-gradient(149deg, rgba(119,172,233,1) 5%, rgba(83,163,255,1) 10%, rgba(46,51,227,1) 41%, rgba(40,51,218,1) 61%, rgba(75,158,255,1) 93%, rgba(124,172,227,1) 98%);
}
.btn-primary-gradient{
background: linear-gradient(to right, #1e85ff 0%, #00a5fa 80%, #00e2fa 100%);
}
.btn-danger-gradient{
background: linear-gradient(to right, #f25858 7%, #ff7840 50%, #ff5140 105%);
}
main .card{
height:calc(100%);
}
main .card-body{
height:calc(100%);
overflow: auto;
padding: 5px;
position: relative;
}
main .container-fluid, main .container-fluid&gt;.row,main .container-fluid&gt;.row&gt;div{
height:calc(100%);
}
#o-list{
height: calc(87%);
overflow: auto;
}
#calc{
position: absolute;
bottom: 1rem;
height: calc(10%);
width: calc(98%);
}
.prod-item{
min-height: 12vh;
cursor: pointer;
}
.prod-item:hover{
opacity: .8;
}
.prod-item .card-body {
display: flex;
justify-content: center;
align-items: center;
}
input[name=&quot;qty[]&quot;]{
width: 30px;
text-align: center
}
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
#cat-list{
height: calc(100%)
}
.cat-item{
cursor: pointer;
}
.cat-item:hover{
opacity: .8;
}
&lt;/style&gt;
&lt;?php 
if(isset($_GET[&#39;id&#39;])):
$order = $conn-&gt;query(&quot;SELECT * FROM orders where id = {$_GET[&#39;id&#39;]}&quot;);
foreach($order-&gt;fetch_array() as $k =&gt; $v){
$$k= $v;
}
$items = $conn-&gt;query(&quot;SELECT o.*,p.name FROM order_items o inner join products p on p.id = o.product_id where o.order_id = $id &quot;);
endif;
?&gt;
&lt;div class=&quot;container-fluid o-field&quot;&gt;
&lt;div class=&quot;row mt-3 ml-3 mr-3&quot;&gt;
&lt;div class=&quot;col-lg-4&quot;&gt;
&lt;div class=&quot;card bg-dark border-primary&quot;&gt;
&lt;div class=&quot;card-header text-white  border-primary&quot;&gt;
&lt;b&gt;Order List&lt;/b&gt;
&lt;span class=&quot;float:right&quot;&gt;&lt;a class=&quot;btn btn-primary btn-sm col-sm-3 float-right&quot; href=&quot;../index.php&quot; id=&quot;&quot;&gt;
&lt;i class=&quot;fa fa-home&quot;&gt;&lt;/i&gt; Home 
&lt;/a&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;div class=&quot;card-body&quot;&gt;
&lt;form action=&quot;&quot; id=&quot;manage-order&quot;&gt;
&lt;input type=&quot;hidden&quot; name=&quot;id&quot; value=&quot;&lt;?php echo isset($_GET[&#39;id&#39;]) ? $_GET[&#39;id&#39;] : &#39;&#39; ?&gt;&quot;&gt;
&lt;div class=&quot;bg-white&quot; id=&#39;o-list&#39;&gt;
&lt;div class=&quot;d-flex w-100 bg-dark mb-1&quot;&gt;
&lt;input type=&quot;number&quot; hidden class=&quot;form-control-sm&quot; name=&quot;order_number&quot; value=&quot;&lt;?php echo isset($order_number) ? $order_number   : &#39;&#39; ?&gt;&quot;&gt;
&lt;/div&gt;
&lt;table class=&quot;table table-bordered bg-light&quot; &gt;
&lt;colgroup&gt;
&lt;col width=&quot;20%&quot;&gt;
&lt;col width=&quot;40%&quot;&gt;
&lt;col width=&quot;40%&quot;&gt;
&lt;col width=&quot;5%&quot;&gt;
&lt;/colgroup&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;QTY&lt;/th&gt;
&lt;th&gt;Order&lt;/th&gt;
&lt;th&gt;Amount&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;?php 
if(isset($items)):
while($row=$items-&gt;fetch_assoc()):
?&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div class=&quot;d-flex&quot;&gt;
&lt;span class=&quot;btn btn-sm btn-secondary btn-minus&quot;&gt;&lt;b&gt;&lt;i class=&quot;fa fa-minus&quot;&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;
&lt;input type=&quot;number&quot; name=&quot;qty[]&quot; id=&quot;&quot; value=&quot;&lt;?php echo $row[&#39;qty&#39;] ?&gt;&quot;&gt;
&lt;span class=&quot;btn btn-sm btn-secondary btn-plus&quot;&gt;&lt;b&gt;&lt;i class=&quot;fa fa-plus&quot;&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;input type=&quot;hidden&quot; name=&quot;item_id[]&quot; id=&quot;&quot; value=&quot;&lt;?php echo $row[&#39;id&#39;] ?&gt;&quot;&gt;
&lt;input type=&quot;hidden&quot; name=&quot;product_id[]&quot; id=&quot;&quot; value=&quot;&lt;?php echo $row[&#39;product_id&#39;] ?&gt;&quot;&gt;&lt;?php echo ucwords($row[&#39;name&#39;]) ?&gt;
&lt;small class=&quot;psmall&quot;&gt; (&lt;?php echo number_format($row[&#39;price&#39;],2) ?&gt;)&lt;/small&gt;
&lt;/td&gt;
&lt;td class=&quot;text-right&quot;&gt;
&lt;input type=&quot;hidden&quot; name=&quot;price[]&quot; id=&quot;&quot; value=&quot;&lt;?php echo $row[&#39;price&#39;] ?&gt;&quot;&gt;
&lt;input type=&quot;hidden&quot; name=&quot;amount[]&quot; id=&quot;&quot; value=&quot;&lt;?php echo $row[&#39;amount&#39;] ?&gt;&quot;&gt;
&lt;span class=&quot;amount&quot;&gt;&lt;?php echo number_format($row[&#39;amount&#39;],2) ?&gt;&lt;/span&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;span class=&quot;btn btn-sm btn-danger btn-rem&quot;&gt;&lt;b&gt;&lt;i class=&quot;fa fa-times text-white&quot;&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;script&gt;
$(document).ready(function(){
qty_func()
calc()
cat_func();
})
&lt;/script&gt;
&lt;?php endwhile; ?&gt;
&lt;?php endif; ?&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&quot;d-block bg-white&quot; id=&quot;calc&quot;&gt;
&lt;table class=&quot;&quot; width=&quot;100%&quot;&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;b&gt;&lt;h4&gt;Total&lt;/h4&gt;&lt;/b&gt;&lt;/td&gt;
&lt;td class=&quot;text-right&quot;&gt;
&lt;input type=&quot;hidden&quot; name=&quot;total_amount&quot; value=&quot;0&quot;&gt;
&lt;input type=&quot;hidden&quot; name=&quot;total_tendered&quot; value=&quot;0&quot;&gt;
&lt;span class=&quot;&quot;&gt;&lt;h4&gt;&lt;b id=&quot;total_amount&quot;&gt;0.00&lt;/b&gt;&lt;/h4&gt;&lt;/span&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;col-lg-8  p-field&quot;&gt;
&lt;div class=&quot;card border-primary&quot;&gt;
&lt;div class=&quot;card-header bg-dark text-white  border-primary&quot;&gt;
&lt;b&gt;Products&lt;/b&gt;
&lt;/div&gt;
&lt;div class=&quot;card-body bg-dark d-flex&quot; id=&#39;prod-list&#39;&gt;
&lt;div class=&quot;col-md-3&quot;&gt;
&lt;div class=&quot;w-100 pr-0 bg-white&quot; id=&quot;cat-list&quot;&gt;
&lt;b&gt;Category&lt;/b&gt;
&lt;hr&gt;
&lt;div class=&quot;card bg-primary mx-3 mb-2 cat-item&quot; style=&quot;height:auto !important;&quot; data-id = &#39;all&#39;&gt;
&lt;div class=&quot;card-body&quot;&gt;
&lt;span&gt;&lt;b class=&quot;text-white&quot;&gt;
All
&lt;/b&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;?php 
$qry = $conn-&gt;query(&quot;SELECT * FROM categories order by name asc&quot;);
while($row=$qry-&gt;fetch_assoc()):
?&gt;
&lt;div class=&quot;card bg-primary mx-3 mb-2 cat-item&quot; style=&quot;height:auto !important;&quot; data-id = &#39;&lt;?php echo $row[&#39;id&#39;] ?&gt;&#39;&gt;
&lt;div class=&quot;card-body&quot;&gt;
&lt;span&gt;&lt;b class=&quot;text-white&quot;&gt;
&lt;?php echo ucwords($row[&#39;name&#39;]) ?&gt;
&lt;/b&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;?php endwhile; ?&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;col-md-9&quot;&gt;
&lt;hr&gt;
&lt;div class=&quot;row&quot;&gt;
&lt;?php
$prod = $conn-&gt;query(&quot;SELECT * FROM products where status = 1 order by name asc&quot;);
while($row=$prod-&gt;fetch_assoc()):
?&gt;
&lt;div class=&quot;col-md-4 mb-2&quot;&gt;
&lt;div class=&quot;card bg-primary prod-item&quot; data-json = &#39;&lt;?php echo json_encode($row) ?&gt;&#39; data-category-id=&quot;&lt;?php echo $row[&#39;category_id&#39;] ?&gt;&quot;&gt;
&lt;div class=&quot;card-body&quot;&gt;
&lt;span&gt;&lt;b class=&quot;text-white&quot;&gt;
&lt;?php echo $row[&#39;name&#39;] ?&gt;
&lt;/b&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;?php endwhile; ?&gt;
&lt;/div&gt;
&lt;/div&gt;   
&lt;/div&gt;
&lt;div class=&quot;card-footer bg-dark  border-primary&quot;&gt;
&lt;div class=&quot;row justify-content-center&quot;&gt;
&lt;div class=&quot;btn btn btn-sm col-sm-3 btn-primary mr-2&quot; type=&quot;button&quot; id=&quot;pay&quot;&gt;Place Order&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;      			
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;modal fade&quot; id=&quot;pay_modal&quot; role=&#39;dialog&#39;&gt;
&lt;div class=&quot;modal-dialog modal-dialog-centered modal-md&quot; role=&quot;document&quot;&gt;
&lt;div class=&quot;modal-content&quot;&gt;
&lt;div class=&quot;modal-header&quot;&gt;
&lt;h5 class=&quot;modal-title&quot;&gt;&lt;b&gt;Pay&lt;/b&gt;&lt;/h5&gt;
&lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;modal&quot; aria-label=&quot;Close&quot;&gt;
&lt;span aria-hidden=&quot;true&quot;&gt;&amp;times;&lt;/span&gt;
&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;modal-body&quot;&gt;
&lt;div class=&quot;container-fluid&quot;&gt;
&lt;div class=&quot;form-group&quot;&gt;
&lt;label for=&quot;&quot;&gt;Amount Payable&lt;/label&gt;
&lt;input type=&quot;number&quot; class=&quot;form-control text-right&quot; id=&quot;apayable&quot; readonly=&quot;&quot; value=&quot;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;form-group&quot;&gt;
&lt;label for=&quot;&quot;&gt;Amount Tendered&lt;/label&gt;
&lt;input type=&quot;text&quot; class=&quot;form-control text-right&quot; id=&quot;tendered&quot; value= &quot;0&quot; autocomplete=&quot;off&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;form-group&quot;&gt;
&lt;label for=&quot;&quot;&gt;Change&lt;/label&gt;
&lt;input type=&quot;text&quot; class=&quot;form-control text-right&quot; id=&quot;change&quot; value=&quot;0.00&quot; readonly=&quot;&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;modal-footer&quot;&gt;
&lt;button type=&quot;submit&quot; class=&quot;btn btn-primary btn-sm&quot;  form=&quot;manage-order&quot;&gt;Pay&lt;/button&gt;
&lt;button type=&quot;button&quot; class=&quot;btn btn-secondary btn-sm&quot; data-dismiss=&quot;modal&quot;&gt;Cancel&lt;/button&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;script&gt;
var total;
cat_func();
$(&#39;#prod-list .prod-item&#39;).click(function(){
var data = $(this).attr(&#39;data-json&#39;)
data = JSON.parse(data)
if($(&#39;#o-list tr[data-id=&quot;&#39;+data.id+&#39;&quot;]&#39;).length &gt; 0){
var tr = $(&#39;#o-list tr[data-id=&quot;&#39;+data.id+&#39;&quot;]&#39;)
var qty = tr.find(&#39;[name=&quot;qty[]&quot;]&#39;).val();
qty = parseInt(qty) + 1;
qty = tr.find(&#39;[name=&quot;qty[]&quot;]&#39;).val(qty).trigger(&#39;change&#39;)
calc()
return false;
}
var tr = $(&#39;&lt;tr class=&quot;o-item&quot;&gt;&lt;/tr&gt;&#39;)
tr.attr(&#39;data-id&#39;,data.id)
tr.append(&#39;&lt;td&gt;&lt;div class=&quot;d-flex&quot;&gt;&lt;span class=&quot;btn btn-sm btn-secondary btn-minus&quot;&gt;&lt;b&gt;&lt;i class=&quot;fa fa-minus&quot;&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;input type=&quot;number&quot; name=&quot;qty[]&quot; id=&quot;&quot; value=&quot;1&quot;&gt;&lt;span class=&quot;btn btn-sm btn-secondary btn-plus&quot;&gt;&lt;b&gt;&lt;i class=&quot;fa fa-plus&quot;&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/td&gt;&#39;) 
tr.append(&#39;&lt;td&gt;&lt;input type=&quot;hidden&quot; name=&quot;item_id[]&quot; id=&quot;&quot; value=&quot;&quot;&gt;&lt;input type=&quot;hidden&quot; name=&quot;product_id[]&quot; id=&quot;&quot; value=&quot;&#39;+data.id+&#39;&quot;&gt;&#39;+data.name+&#39; &lt;small class=&quot;psmall&quot;&gt;(&#39;+(parseFloat(data.price).toLocaleString(&quot;en-US&quot;,{style:&#39;decimal&#39;,minimumFractionDigits:2,maximumFractionDigits:2}))+&#39;)&lt;/small&gt;&lt;/td&gt;&#39;) 
tr.append(&#39;&lt;td class=&quot;text-right&quot;&gt;&lt;input type=&quot;hidden&quot; name=&quot;price[]&quot; id=&quot;&quot; value=&quot;&#39;+data.price+&#39;&quot;&gt;&lt;input type=&quot;hidden&quot; name=&quot;amount[]&quot; id=&quot;&quot; value=&quot;&#39;+data.price+&#39;&quot;&gt;&lt;span class=&quot;amount&quot;&gt;&#39;+(parseFloat(data.price).toLocaleString(&quot;en-US&quot;,{style:&#39;decimal&#39;,minimumFractionDigits:2,maximumFractionDigits:2}))+&#39;&lt;/span&gt;&lt;/td&gt;&#39;) 
tr.append(&#39;&lt;td&gt;&lt;span class=&quot;btn btn-sm btn-danger btn-rem&quot;&gt;&lt;b&gt;&lt;i class=&quot;fa fa-times text-white&quot;&gt;&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;&#39;)
$(&#39;#o-list tbody&#39;).append(tr)
qty_func()
calc()
cat_func();
})
function qty_func(){
$(&#39;#o-list .btn-minus&#39;).click(function(){
var qty = $(this).siblings(&#39;input&#39;).val()
qty = qty &gt; 1 ? parseInt(qty) - 1 : 1;
$(this).siblings(&#39;input&#39;).val(qty).trigger(&#39;change&#39;)
calc()
})
$(&#39;#o-list .btn-plus&#39;).click(function(){
var qty = $(this).siblings(&#39;input&#39;).val()
qty = parseInt(qty) + 1;
$(this).siblings(&#39;input&#39;).val(qty).trigger(&#39;change&#39;)
calc()
})
$(&#39;#o-list .btn-rem&#39;).click(function(){
$(this).closest(&#39;tr&#39;).remove()
calc()
})
}
function calc(){
$(&#39;[name=&quot;qty[]&quot;]&#39;).each(function(){
$(this).change(function(){
var tr = $(this).closest(&#39;tr&#39;);
var qty = $(this).val();
var price = tr.find(&#39;[name=&quot;price[]&quot;]&#39;).val()
var amount = parseFloat(qty) * parseFloat(price);
tr.find(&#39;[name=&quot;amount[]&quot;]&#39;).val(amount)
tr.find(&#39;.amount&#39;).text(parseFloat(amount).toLocaleString(&quot;en-US&quot;,{style:&#39;decimal&#39;,minimumFractionDigits:2,maximumFractionDigits:2}))
})
})
var total = 0;
$(&#39;[name=&quot;amount[]&quot;]&#39;).each(function(){
total = parseFloat(total) + parseFloat($(this).val()) 
})
console.log(total)
$(&#39;[name=&quot;total_amount&quot;]&#39;).val(total)
$(&#39;#total_amount&#39;).text(parseFloat(total).toLocaleString(&quot;en-US&quot;,{style:&#39;decimal&#39;,minimumFractionDigits:2,maximumFractionDigits:2}))
}
function cat_func(){
$(&#39;.cat-item&#39;).click(function(){
var id = $(this).attr(&#39;data-id&#39;)
console.log(id)
if(id == &#39;all&#39;){
$(&#39;.prod-item&#39;).parent().toggle(true)
}else{
$(&#39;.prod-item&#39;).each(function(){
if($(this).attr(&#39;data-category-id&#39;) == id){
$(this).parent().toggle(true)
}else{
$(this).parent().toggle(false)
}
})
}
})
}
$(&#39;#save_order&#39;).click(function(){
$(&#39;#tendered&#39;).val(&#39;&#39;).trigger(&#39;change&#39;)
$(&#39;[name=&quot;total_tendered&quot;]&#39;).val(&#39;&#39;)
$(&#39;#manage-order&#39;).submit()
})
$(&quot;#pay&quot;).click(function(){
start_load()
var amount = $(&#39;[name=&quot;total_amount&quot;]&#39;).val()
if($(&#39;#o-list tbody tr&#39;).length &lt;= 0){
alert_toast(&quot;Please add atleast 1 product first.&quot;,&#39;danger&#39;)
end_load()
return false;
}
$(&#39;#apayable&#39;).val(parseFloat(amount).toLocaleString(&quot;en-US&quot;,{style:&#39;decimal&#39;,minimumFractionDigits:2,maximumFractionDigits:2}))
$(&#39;#pay_modal&#39;).modal(&#39;show&#39;)
setTimeout(function(){
$(&#39;#tendered&#39;).val(&#39;&#39;).trigger(&#39;change&#39;)
$(&#39;#tendered&#39;).focus()
end_load()
},500)
})
$(&#39;#tendered&#39;).keyup(&#39;input&#39;,function(e){
if(e.which == 13){
$(&#39;#manage-order&#39;).submit();
return false;
}
var tend = $(this).val()
tend =tend.replace(/,/g,&#39;&#39;) 
$(&#39;[name=&quot;total_tendered&quot;]&#39;).val(tend)
if(tend == &#39;&#39;)
$(this).val(&#39;&#39;)
else
$(this).val((parseFloat(tend).toLocaleString(&quot;en-US&quot;)))
tend = tend &gt; 0 ? tend : 0;
var amount=$(&#39;[name=&quot;total_amount&quot;]&#39;).val()
var change = parseFloat(tend) - parseFloat(amount)
$(&#39;#change&#39;).val(parseFloat(change).toLocaleString(&quot;en-US&quot;,{style:&#39;decimal&#39;,minimumFractionDigits:2,maximumFractionDigits:2}))
})
$(&#39;#tendered&#39;).on(&#39;input&#39;,function(){
var val = $(this).val()
val = val.replace(/[^0-9 \,]/, &#39;&#39;);
$(this).val(val)
})
$(&#39;#manage-order&#39;).submit(function(e){
e.preventDefault();
start_load()
$.ajax({
url:&#39;../ajax.php?action=save_order&#39;,
method:&#39;POST&#39;,
data:$(this).serialize(),
success:function(resp){
if(resp &gt; 0){
if($(&#39;[name=&quot;total_tendered&quot;]&#39;).val() &gt; 0){
alert_toast(&quot;Data successfully saved.&quot;,&#39;success&#39;)
setTimeout(function(){
var nw = window.open(&#39;../receipt.php?id=&#39;+resp,&quot;_blank&quot;,&quot;width=900,height=600&quot;)
setTimeout(function(){
nw.print()
setTimeout(function(){
nw.close()
location.reload()
},500)
},500)
},500)
}else{
alert_toast(&quot;Data successfully saved.&quot;,&#39;success&#39;)
setTimeout(function(){
location.reload()
},500)
}
}
}
})
})
&lt;/script&gt;

I tried to change the value="" of the input for Amount Tendered but it never showed.

Tried to put the ID of the Amount Payable as the Amount tendered as Value but nothing

答案1

得分: 0

如何

```javascript
$(&#39;#tendered&#39;).on(&#39;change input&#39;, function() {
    $(&#39;#apayable&#39;).val($(this).val())
})

如果DOM发生变化,并且上述代码不起作用

$(document).on(&#39;change input&#39;,&#39;#tendered&#39;, function() {
    $(&#39;#apayable&#39;).val($(this).val())
})

<details>
<summary>英文:</summary>
How about 
```javascript
$(&#39;#tendered&#39;).on(&#39;change input&#39;, function() {
$(&#39;#apayable&#39;).val($(this).val())
})

And if there are changes to the DOm and the above does not work

$(document).on(&#39;change input&#39;,&#39;#tendered&#39;, function() {
    $(&#39;#apayable&#39;).val($(this).val())
})

答案2

得分: 0

我成功修复了它。

通过更改"收款"文本框的起始值。

以前:

$(&#39;#apayable&#39;).val(parseFloat(amount).toLocaleString(&quot;en-US&quot;,{style:&#39;decimal&#39;,minimumFractionDigits:2,maximumFractionDigits:2}))
$(&#39;#pay_modal&#39;).modal(&#39;show&#39;)
setTimeout(function(){
    $(&#39;#tendered&#39;).val(&#39;&#39;).trigger(&#39;change&#39;)
    $(&#39;#tendered&#39;).focus()
    end_load()
},500)

现在已更正:

$(&#39;#apayable&#39;).val(parseFloat(amount).toLocaleString(&quot;en-US&quot;,{style:&#39;decimal&#39;,minimumFractionDigits:2,maximumFractionDigits:2}))
$(&#39;#pay_modal&#39;).modal(&#39;show&#39;)
setTimeout(function(){
    $(&#39;#tendered&#39;).val(parseFloat(amount).toLocaleString(&quot;en-US&quot;,{style:&#39;decimal&#39;,minimumFractionDigits:2,maximumFractionDigits:2}))
    $(&#39;#tendered&#39;).focus()
    end_load()
},500)
英文:

I was able to fix it.

by changing the starting value of the Tendered Text Box

Previously:

$(&#39;#apayable&#39;).val(parseFloat(amount).toLocaleString(&quot;en-US&quot;,{style:&#39;decimal&#39;,minimumFractionDigits:2,maximumFractionDigits:2}))
$(&#39;#pay_modal&#39;).modal(&#39;show&#39;)
setTimeout(function(){
$(&#39;#tendered&#39;).val(&#39;&#39;).trigger(&#39;change&#39;)
$(&#39;#tendered&#39;).focus()
end_load()
},500)

Now corrected

$(&#39;#apayable&#39;).val(parseFloat(amount).toLocaleString(&quot;en-US&quot;,{style:&#39;decimal&#39;,minimumFractionDigits:2,maximumFractionDigits:2}))
$(&#39;#pay_modal&#39;).modal(&#39;show&#39;)
setTimeout(function(){
$(&#39;#tendered&#39;).val(parseFloat(amount).toLocaleString(&quot;en-US&quot;,{style:&#39;decimal&#39;,minimumFractionDigits:2,maximumFractionDigits:2}))
$(&#39;#tendered&#39;).focus()
end_load()
},500)

huangapple
  • 本文由 发表于 2023年6月16日 00:05:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76483537.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定