JavaScript代码在文本框中显示div消息 - javascript

以下是我用来计算总计的脚本。

<script type="text/javascript" >
    function calculateTotal() {
        // price per unit 
        var priceEL = document.getElementById('price');
        // get input element from DOM
        var inputEl = document.getElementById('quantity');
        // read quantity from the input element (it is read as a string)

         var priceSting = priceEL.value;
        var quantitySting = inputEl.value;
        // convert string value from the form element into integer (or float if needed)
        var quantity = parseInt(quantitySting);
        var price = parseInt(priceSting);
        // calculate total
        var total = price * quantity;
        // get element that displays total from DOM
        var displayEl = document.getElementById('total')
        // display total value in target element
        displayEl.innerHTML = total;
    }
</script>

现在我的代码在div标签内回显总值...如下

<div id ="total"></div>

我需要在文本框下面显示总计。

<input type="textbox" name="total" id ="total"></td>

参考方案

尝试这个:

document.getElementById("total").value = total;

PHP json_encode数组到javascript关联数组 - javascript

我有一些从PHP中读取的mysqli列。它正在完美地获取和回显。$results = mysqli_fetch_assoc(mysqli_query($conn, $querystring)); echo json_encode($results); //$results = {"title":"Sea Shells"…

PHP-显示特殊字符 - javascript

允许用户输入的代码段//fetch user input and pass it in URL alertify.prompt("Please enter note/remarks for this Form (optional):", function (e,value) { if (e) { alertify.success(…

Mongo汇总 - javascript

我的收藏中有以下文件{ "_id": ObjectId("54490b8104f7142f22ecc97f"), "title": "Sample1", "slug": "samplenews", "cat": …

验证php中的javascript对象 - php

在我的用户界面中,用户可以构建一些javascript对象,例如:var box = { "width": "100px", "height": "200px", "click": function () { alert("You clicked t…

和字符中断通过PHP接收JSON - javascript

我有一个包含更多对象的数组。如果一个对象包含&字符,则php不会接收&之后的每个对象。可能是什么问题?这就是阿贾克斯xmlhttp.open("POST", "get.php"); xmlhttp.setRequestHeader("Content-Type", "application/…