简体   繁体   English

如何更改输入文本值已在javascript中设置

[英]how to change input text value has been set in javascript

i want asking about javascript. 我想问一下JavaScript。 i develop a tax calculation system. 我开发了一个税收计算系统。

function countsisa(){
    var iv = document.getElementById("invoicevalue");
    var ppn = document.getElementById("ppn");
    var pph = document.getElementById("pph");
    var dpp = document.getElementById("dpp");
    var propv = document.getElementById("propertyvalue");
    var shipv = document.getElementById("shippingvalue");
    var dppship = document.getElementById("dppshipping");
    var pph23 = document.getElementById("pph23");
    var total = document.getElementById("total");
    var income = document.getElementById("income");
    var ppndoc = document.getElementById("ppndoc");
    var pphdoc = document.getElementById("pphdoc");
    var pphdoc23 = document.getElementById("pphdoc23");

    if(iv.value.replace(/[.*+?^${}()|[\]\\]/g,"") > 0){
        document.getElementById("propertyvalue").disabled = true;
        document.getElementById("shippingvalue").disabled = true;
        document.getElementById("dppshipping").disabled = true;
        document.getElementById("pph23").disabled = true;

        dpp.value = Math.ceil(iv.value.replace(/[.*+?^${}()|[\]\\]/g,"") / 1.1);
        pph.value = Math.ceil(dpp.value.replace(/[.*+?^${}()|[\]\\]/g,"") * 0.015);
        ppn.value = Math.ceil(dpp.value.replace(/[.*+?^${}()|[\]\\]/g,"") * 0.10);
        income.value = iv.value.replace(/[.*+?^${}()|[\]\\]/g,"")-pph.value-ppn.value;
    }else{
        if(propv.value.replace(/[.*+?^${}()|[\]\\]/g,"") > 0){
            document.getElementById("invoicevalue").disabled = true;
            total = parseFloat(propv.value.replace(/[.*+?^${}()|[\]\\]/g,""),10)+parseFloat(shipv.value.replace(/[.*+?^${}()|[\]\\]/g,""),10);
            // total = String(total);
            propv.value = String(propv.value);
            shipv.value = String(shipv.value);
            dpp.value = Math.ceil(propv.value.replace(/[.*+?^${}()|[\]\\]/g,"") / 1.1);
            dppship.value = Math.ceil(shipv.value.replace(/[.*+?^${}()|[\]\\]/g,"") / 1.1);
            pph.value = Math.ceil(dpp.value.replace(/[.*+?^${}()|[\]\\]/g,"") * 0.015);
            pph23.value = Math.ceil(dppship.value.replace(/[.*+?^${}()|[\]\\]/g,"") * 0.02);
            ppn.value = (propv.value.replace(/[.*+?^${}()|[\]\\]/g,"") - dpp.value)+(shipv.value.replace(/[.*+?^${}()|[\]\\]/g,"")-dppship.value);
            income.value = total-pph.value-ppn.value-pph23.value;
        }else{
            document.getElementById("propertyvalue").disabled = false;
            document.getElementById("shippingvalue").disabled = false;
            document.getElementById("dppshipping").disabled = false;
            document.getElementById("pph23").disabled = false;
        }
    }
    console.log(total);

    if(dpp.value <= 0){
        dpp.value = 0;
    }
    if(dppship.value <= 0){
        dppship.value = 0;
    }
    if(pph.value <= 0){
        pph.value = 0;
    }

    if(pph23.value <= 0){
        pph23.value = 0;
    }
    if(ppn.value <= 0){
        ppn.value = 0;
    }

    if(income.value <= 0){
        income.value = 0;
    }

    dppship.value = tandaPemisahTitik(dppship.value);
    dpp.value = tandaPemisahTitik(dpp.value);
    pph.value = tandaPemisahTitik(pph.value);
    pph23.value = tandaPemisahTitik(pph23.value);
    ppn.value = tandaPemisahTitik(ppn.value);
    pphdoc.value = tandaPemisahTitik(pph.value.replace(/[.*+?^${}()|[\]\\]/g,""));
    pphdoc23.value = tandaPemisahTitik(pph23.value.replace(/[.*+?^${}()|[\]\\]/g,""));
    ppndoc.value = tandaPemisahTitik(ppn.value);
    income.value = tandaPemisahTitik(income.value);


}

this my javascript code to count value and display it in input value. 这是我的JavaScript代码以计算值并将其显示在输入值中。

                                            <div class="form-group">
                                                <label class="control-label col-md-3 col-sm-3 col-xs-12" for="ppn"><?php print _('mi_invoice_ppn'); ?></label>
                                                <div class="col-md-6 col-sm-6 col-xs-12">
                                                    <div class="input-group">
                                                            <span class="input-group-addon" style="border-radius:0px;">Rp</span>
                                                            <input type="text" name="ppn" id="ppn" class="form-control" onkeydown="return numbersonly(this, event);" onkeyup="javascript:tandaPemisahTitik(this);" placeholder="0" />
                                                    </div>
                                                </div>
                                            </div>

this is the input code. 这是输入代码。 i want change input text value has been count in javascript function. 我想更改输入文本值已计入javascript函数。 i want to manually changed again. 我想再次手动更改。 so javascript function to count automatic. 因此javascript函数自动计数。 and can edit again if miscalculation. 如果计算错误,可以再次编辑。

If you want to recalculate when any input value's changed, you can add change listener on the input elements. 如果要在任何输入值更改时重新计算,则可以在输入元素上添加change侦听器。

will be look like: 看起来像:

let inputElems = document.querySelectorAll("input");
for (let i = 0, len = inputElems.length; i < len; i++) {
  inputElems[i].addEventListener("change", countsisa);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果数据属性(HTML)=== javascript 中的输入文本,如何更改已写入输入的每个字母的 javascript 颜色? - How can I change color in javascript for each letter which has been written into an input if data attribute(HTML) === input text in javascript? RequiredFieldValidator无法看到已由javascript设置的文本 - RequiredFieldValidator not see text has been set by javascript 如何检查更改时的文本输入字符串是否具有大写字母 Javascript - How to check if a text input string on change has an Uppercase letter Javascript 如何检查更改时的文本输入字符串是否具有小写字母 Javascript - How to check if a text input string on change has a Lowercase letter Javascript 如何使用 Javascript 检查更改时的文本输入字符串是否有数字 - How to check if a text input string on change has a number using Javascript 如何将 php 数据设置为 javascript 日期并更改输入文本的颜色 - How to set php data to javascript date and change color of the input text 如何更改使用ajax调用附加的html输入的span值? - How to change span value from a html input which has been appended using ajax call? 使用JavaScript选择文件后,如何更改HTML标签文本 - How do I change HTML Label Text Once File Has Been Selected using Javascript 我如何转移已输入的值 <input number> 对象转换成javascript而不刷新页面? - How can i transfer value which has been typed in <input number> object into javascript without page refreshing? JavaScript-如何在点击事件回调函数中将输入值更新为“”时清空输入字段 - JavaScript - How to empty the input field when it value has been updated to “ ” in a click event callback function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM