CodeIgniter中的表单计算

时间:2016-06-19 17:29:31

标签: javascript forms codeigniter

我想要做的是在输入数量后,余额和数量应该添加并自动平衡答案。这是一个codeigniter项目。余额来自数据库。

<form action="addnew" method="post">
    <input   type="text" name="io" placeholder="IN_OUT"><br>
    <input type="date" name="date" placeholder="Date yyyy-mm-dd" value="<?php echo date("Y-m-d") ?>" disabled><br>
    <input id="qty" type="number" name="qty" placeholder="Quantity"><?php echo $key->ns_balance; ?><br>
    <input type="text" name="breed" placeholder="Breed"><br>
    <input type="number" name="es_id" placeholder="Estate"><br>
    <input type="number"
           name="balance"
           placeholder="Balance"
           value="" disabled>
    <br>
    <input type="submit" name="submit" value="Submit">
    <input type="reset" name="Reset" value="Reset"
</form>

User interface image

1 个答案:

答案 0 :(得分:0)

尝试使用此jquery代码:

<div id="test"><input id="qty" type="number" name="qty" placeholder="Quantity"><?php echo $key->ns_balance; ?></div>
<input id="balance" type="hidden" value="<?php echo $key->ns_balance; ?>">
$("#qty").on("keyup", function(){
 var qty = $("#qty").val();
 var balance= parseInt($("#balance").val());

 $("#test").text("Balance -"+qty*balance); //you can change the id to place result whereever you want
});