[英]Onchange Ajax method to load values from database work correct but how to change textarea value multiply with another textbox value
我正在使用Ajax调用将数据库中的变化值装入一个文本区域,其中所有值及其数量都在一个文本区域中。 现在,我想更改此文本区域值,以便在另一个文本框中输入一个值并乘以该文本区域的所有数量值时进行更改。 我是JavaScript和Ajax的新手,请帮助我。 这是我的代码。
$(document).ready(function () {
$('#location').change(function () {
$.ajax({
url: 'location.php?location=' + $(this).val(),
type: "get",
timeout: 10000,
dataType: 'json',
success: function (data) {
var material_name = data.material_name;
var material_quantity = data.product_quantity;
var data_material = "";
for(var i = 0; i < material_name.length; i++) {
data_material += material_name[i] + " : " + material_quantity[i] + " ";
}
document.getElementById("material_name").value = data_material;
document.getElementById("material_quantity1").value = data.product_quantity;
},
error: function () {}
});
$('#quantity').keyup(function () {
var price = document.getElementById('material_quantity').value;
//document.getElementById("price_hidden").value=price;
var quantity = document.getElementById("quantity").value;
var total = quantity * price;
document.getElementById("total").value = total;
document.getElementById("total_hidden").value = document.getElementById("total").value;
});
});
});
当我在其他文本框中输入任何数量时,我想更改ID为#material_quantity1值的文本框的所有值。 就像在我的文本框中一样,如果输入5,我现在有15,20,25,那么它将显示75,100,125。
$('#textarea1').live('blur',function(){ // Textarea in which you will enter the value..
var textarea1 = $('#textarea').val(); // Textarea which will contain 152025..
// if your value containts commas then you can use $('#textarea').val().replace(/,/g , ""); instead of $('#textarea').val();
var final_value = $(this).val()*textarea1; // Put this value in the textarea you want...
});
//Add the below function this will replace your numbers with commas
function ReplaceNumberWithCommas(param1) {
var x=param1.toString();
var lastThree = x.substring(x.length-3);
var otherNumbers = x.substring(0,x.length-3);
if(otherNumbers != '')
lastThree = ',' + lastThree;
var res = otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree;
return res;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.