我需要在文本框中键入值时调用函数(I need to call a function when value is typed in textbox)
当在文本框中输入输入并在另一个文本框中查看结果时,我需要调用函数税。 我正在使用codeigniter和mysql。 我写了一个功能税
<?php function tax($amount_without_tax, $tax){ $amount_with_tax = $amount_without_tax + ($tax*($amount_without_tax/100)); // work out the amount of vat $amount_with_tax = round($amount_with_tax, 2); return $amount_with_tax; } ?>我有一个类似的文本框
<input type="number" name="product_price"/>当我在上面的文本框中键入内容并将其显示在另一个文本框中时,如何调用此函数有人可以帮助我...
I need to call a function tax when input is typed in a text box and view the result in another textbox. I am using codeigniter and mysql. I wrote a function tax like
<?php function tax($amount_without_tax, $tax){ $amount_with_tax = $amount_without_tax + ($tax*($amount_without_tax/100)); // work out the amount of vat $amount_with_tax = round($amount_with_tax, 2); return $amount_with_tax; } ?>And i have a textbox like
<input type="number" name="product_price"/>how do i call this function when i type something in the above text box and display them in another textbox Can someone help me...
最满意答案
这段代码适合我
<script type="text/javascript"> function getOrderTotal() { var icost = document.myform.myprice.value; var itax = getSalesTax(); var recurrency = '^[0-9]{1,5}\.[0-9]{2}$'; var reitems = '^([1-9])([0-9]{0,2})$'; if(!icost.match(recurrency)) { alert('Please provide an item cost in 0.00 format!'); } else { var itotal = (icost) * itax; itotal *= 100; itotal = Math.ceil(itotal); itotal /= 100; if(itotal.toFixed) { itotal = itotal.toFixed(2); } document.getElementById('mytotal').value = itotal; } } function getSalesTax() { var taxarray = document.myform.mytax; //var retax = '^[1]{1}\.[0-9]{1,4}$'; var i; for(i=0; i<taxarray.length; i++) { if(taxarray[i].checked) { if(!taxarray[i].value) { alert('Please provide a tax rate from the button list only!'); return 0; } else { return parseFloat(taxarray[i].value); } } } return 1.0; } </script>上面是我的脚本我使用了文本字段并显示了结果
<div class="control-group"> <label for="inputError" class="control-label">Wholesale Price</label> <div class="controls"> <input name="myprice" type="text" id="myprice" size="10" maxlength="10" onChange="getOrderTotal()" value="0.00" /> </div> </div> <div class="control-group"> <label for="inputError" class="control-label">Total amount</label> <div class="controls"> <input type="text" id="mytotal" name="mytotal" value="0.00"> <!--<span class="help-inline">Cost Price</span>--> </div> <div class="control-group"> <label for="inputError" class="control-label">Tax Details</label> <input name="mytax" type="radio" value="0.145" onClick="getOrderTotal()"/> VAT <br /> <input name="mytax" type="radio" value="0.1725" onClick="getOrderTotal()"/> CST <br /> <input name="mytax" type="radio" value="1.00" onClick="getOrderTotal()" checked="checked"/> Other (no sales tax) </br> <!--<span class="help-inline">Cost Price</span>--> </div> </div>谢谢大家的支持.... :)
This code works for me
<script type="text/javascript"> function getOrderTotal() { var icost = document.myform.myprice.value; var itax = getSalesTax(); var recurrency = '^[0-9]{1,5}\.[0-9]{2}$'; var reitems = '^([1-9])([0-9]{0,2})$'; if(!icost.match(recurrency)) { alert('Please provide an item cost in 0.00 format!'); } else { var itotal = (icost) * itax; itotal *= 100; itotal = Math.ceil(itotal); itotal /= 100; if(itotal.toFixed) { itotal = itotal.toFixed(2); } document.getElementById('mytotal').value = itotal; } } function getSalesTax() { var taxarray = document.myform.mytax; //var retax = '^[1]{1}\.[0-9]{1,4}$'; var i; for(i=0; i<taxarray.length; i++) { if(taxarray[i].checked) { if(!taxarray[i].value) { alert('Please provide a tax rate from the button list only!'); return 0; } else { return parseFloat(taxarray[i].value); } } } return 1.0; } </script>Above is my script I used text fields and displayed the results
<div class="control-group"> <label for="inputError" class="control-label">Wholesale Price</label> <div class="controls"> <input name="myprice" type="text" id="myprice" size="10" maxlength="10" onChange="getOrderTotal()" value="0.00" /> </div> </div> <div class="control-group"> <label for="inputError" class="control-label">Total amount</label> <div class="controls"> <input type="text" id="mytotal" name="mytotal" value="0.00"> <!--<span class="help-inline">Cost Price</span>--> </div> <div class="control-group"> <label for="inputError" class="control-label">Tax Details</label> <input name="mytax" type="radio" value="0.145" onClick="getOrderTotal()"/> VAT <br /> <input name="mytax" type="radio" value="0.1725" onClick="getOrderTotal()"/> CST <br /> <input name="mytax" type="radio" value="1.00" onClick="getOrderTotal()" checked="checked"/> Other (no sales tax) </br> <!--<span class="help-inline">Cost Price</span>--> </div> </div>Thank you all for your support.... :)
更多推荐
发布评论