我正在使用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的文本框的所有值。就像在我的文本框中一样,我现在有15,20,25。如果我输入5,它将显示75100125。
$('#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;
}