javascript - ReferenceError: updateGross 未定义 javascript
问题描述
我的javascript有问题。在控制台里面写:
我有一个税级下拉列表 (20%,10%) 我有一个不含税价格的字段
控制台写:ReferenceError: updateGross is not defined --- onkeyup
那里有我的代码
剧本
<script type="text/javascript">
var tax_rates = new Array();
<?php
for ($i=0, $n=count($tax_class_drop_down); $i<$n; $i++) {
if ($tax_class_drop_down[$i]['id'] > 0) {
echo 'tax_rates["' . $tax_class_drop_down[$i]['id'] . '"] = ' . $tax->getTaxRateValue($tax_class_drop_down[$i]['id']) . ';' . "\n";
}
}
?>
function doRound(x, places) {
return Math.round(x * Math.pow(10, places)) / Math.pow(10, places) ;
}
function getTaxRate() {
var selected_value = document.forms["new_product"].products_tax_class_id.selectedIndex;
var parameterVal = document.forms["new_product"].products_tax_class_id[selected_value].value;
if ( (parameterVal > 0) && (tax_rates[parameterVal] > 0) ) {
return tax_rates[parameterVal];
} else {
return 0;
}
}
function updateGross() {
var taxRate = getTaxRate();
var grossValue = document.forms["new_product"].products_price.value;
if (taxRate > 0) {
grossValue = grossValue * ((taxRate / 100) + 1);
}
<?php
if (MODE_B2B_B2C == 'true') {
$QcustomersGroup = $OSCOM_Products->db->prepare('select distinct customers_group_id,
customers_group_name,
customers_group_discount
from :table_customers_groups
where customers_group_id != 0
order by customers_group_id
');
$QcustomersGroup->execute();
while ($QcustomersGroup->fetch() ) {
?>
var grossValue<?php echo $QcustomersGroup->valueInt('customers_group_id'); ?> = document.forms["new_product"].price<?php echo $QcustomersGroup->valueInt('customers_group_id'); ?>.value;
if (taxRate > 0) {
grossValue<?php echo $QcustomersGroup->valueInt('customers_group_id'); ?> = grossValue<?php echo $QcustomersGroup->valueInt('customers_group_id'); ?> * ((taxRate / 100) + 1);
}
document.forms["new_product"].price_gross<?php echo $QcustomersGroup->valueInt('customers_group_id'); ?>.value = doRound(grossValue<?php echo $QcustomersGroup->valueInt('customers_group_id'); ?>, 4);
<?php
}
}
?>
document.forms["new_product"].products_price_gross.value = doRound(grossValue, 4);
}
function updateMargin() {
var grossValue = document.forms["new_product"].products_price.value; // valeur net du prix
var costValue = document.forms["new_product"].products_cost.value; // cout d'achat
var handlingValue = document.forms["new_product"].products_handling.value; // manutention ou autres frais
if (isNaN(costValue)) costValue=0;
if (isNaN(handlingValue)) handlingValue=0;
marginValue = 100 - ((( parseInt(costValue) + parseInt(handlingValue)) / parseInt(grossValue)) * 100);
marginValue = Math.round(marginValue,2);
document.getElementById('products_price_margins').innerHTML = marginValue + "%";
}
function updateNet() {
var taxRate = getTaxRate();
var netValue = document.forms["new_product"].products_price_gross.value;
if (taxRate > 0) {
netValue = netValue / ((taxRate / 100) + 1);
}
<?php
if (MODE_B2B_B2C == 'true') {
$QcustomersGroup = $OSCOM_Products->db->prepare('select distinct customers_group_id,
customers_group_name,
customers_group_discount
from :table_customers_groups
where customers_group_id != 0
order by customers_group_id
');
$QcustomersGroup->execute();
while ($QcustomersGroup->fetch() ) {
?>
var netValue<?php echo $QcustomersGroup->valueInt('customers_group_id'); ?> = document.forms["new_product"].price_gross<?php echo $QcustomersGroup->valueInt('customers_group_id'); ?>.value;
if (taxRate > 0) {
netValue<?php echo $QcustomersGroup->valueInt('customers_group_id'); ?> = netValue<?php echo $QcustomersGroup->valueInt('customers_group_id'); ?> / ((taxRate / 100) + 1);
}
document.forms["new_product"].price<?php echo $QcustomersGroup->valueInt('customers_group_id'); ?>.value = doRound(netValue<?php echo $QcustomersGroup->valueInt('customers_group_id'); ?>, 4);
<?php
}
}
?>
document.forms["new_product"].products_price.value = doRound(netValue, 4);
}
</script>
含税和不含税价格的 HTML 代码
<div class="col-md-5">
<div class="form-group row">
<label for="<?php echo $OSCOM_Products->getDef('text_products_price'); ?>" class="col-5 col-form-label"><?php echo $OSCOM_Products->getDef('text_products_price'); ?></label>
<div class="col-md-5">
<?php
if (DISPLAY_DOUBLE_TAXE == 'false') {
echo HTML::inputField('products_price', $pInfo->products_price, 'id="products_price" onkeyup="updateGross()"') . '<strong>' . $OSCOM_Products->getDef('text_products_price_net') . '</strong>';
} else {
echo HTML::inputField('products_price', $pInfo->products_price, 'id="products_price" onkeyup="updateGross()"') . '<strong>' . $OSCOM_Products->getDef('text_products_price_net') . '</strong>';
}
if (DISPLAY_DOUBLE_TAXE == 'false') {
echo HTML::inputField('products_price_gross', $pInfo->products_price, 'id="products_price_gross" onkeyup="updateNet()"') . '<strong>' . $OSCOM_Products->getDef('text_products_price_gross') . '</strong>';
}
?>
</div>
</div>
</div>
<script type="text/javascript">
updateGross();
</script>
le js généré : le problème peut venir de la ou il n'y a pas de valeur :
tax_rates["3"] = 0;
tax_rates["4"] = 0;
tax_rates["1"] = 0;
tax_rates["2"] = 0;
var tax_rates = new Array();
tax_rates["3"] = 0;
tax_rates["4"] = 0;
tax_rates["1"] = 0;
tax_rates["2"] = 0;
function doRound(x, places) {
return Math.round(x * Math.pow(10, places)) / Math.pow(10, places) ;
}
function getTaxRate() {
var selected_value = document.forms["new_product"].products_tax_class_id.selectedIndex;
var parameterVal = document.forms["new_product"].products_tax_class_id[selected_value].value;
if ( (parameterVal > 0) && (tax_rates[parameterVal] > 0) ) {
return tax_rates[parameterVal];
} else {
return 0;
}
}
function updateGross() {
var taxRate = getTaxRate();
var grossValue = document.forms["new_product"].products_price.value;
if (taxRate > 0) {
grossValue = grossValue * ((taxRate / 100) + 1);
}
var grossValue1 = document.forms["new_product"].price1.value;
if (taxRate > 0) {
grossValue1 = grossValue1 * ((taxRate / 100) + 1);
}
document.forms["new_product"].price_gross1.value = doRound(grossValue1, 4);
document.forms["new_product"].products_price_gross.value = doRound(grossValue, 4);
}
/********************************/
/* Margin report */
/********************************/
function updateMargin() {
var grossValue = document.forms["new_product"].products_price.value; // valeur net du prix
var costValue = document.forms["new_product"].products_cost.value; // cout d'achat
var handlingValue = document.forms["new_product"].products_handling.value; // manutention ou autres frais
if (isNaN(costValue)) costValue=0;
if (isNaN(handlingValue)) handlingValue=0;
marginValue = 100 - ((( parseInt(costValue) + parseInt(handlingValue)) / parseInt(grossValue)) * 100);
marginValue = Math.round(marginValue,2);
document.getElementById('products_price_margins').innerHTML = marginValue + "%";
}
function updateNet() {
var taxRate = getTaxRate();
var netValue = document.forms["new_product"].products_price_gross.value;
if (taxRate > 0) {
netValue = netValue / ((taxRate / 100) + 1);
}
var netValue1 = document.forms["new_product"].price_gross1.value;
if (taxRate > 0) {
netValue1 = netValue1 / ((taxRate / 100) + 1);
}
document.forms["new_product"].price1.value = doRound(netValue1, 4);
document.forms["new_product"].products_price.value = doRound(netValue, 4);
}
解决方案
推荐阅读
- bots - 用于企业必应搜索的必应 Web 搜索 API
- python - Django - 当我在尝试提交表单时遇到错误时,为什么会出现这种随机文本呈现?
- image - 使用 tiffcp 控制文件顺序
- java - 单元测试 AWS SNS 发布消息
- join - Hive 加入分区
- python - 使用“is”标识而不是“==”相等来检查对象是否在可迭代中
- python - Python Graphene 处理多对多关系
- angular - 如何处理仅在验证成功时才应返回 Observable 的函数?
- java - TabLayout 上的标签标题未显示
- sql - 如何使用 ifelse 在 AWS QuickSight 中编写计算字段公式