I'm having a lot of difficulty in updating a cakephp input, based on other inputs within the same cakephp form. Here is the code to form:
echo $this->Form->input('UnitPrice',['id'=>'unitPrice', 'type' => 'number']);
echo $this->Form->input('SalePercent', ['id'=>'salePercent', 'type'=>'number']);
echo $this->Form->input('SalePrice', ['id'=>'salePrice', 'readonly'=>'readonly']);
Here is the jscript:
$('#salePercent').on('input', function() {
calculate();
});
function calculate(){
var sPercent = parseInt($('#salePercent').val());
var sPrice="";
if(isNaN(uPrice) || isNaN(sPercent)){
sPrice=" ";
}else{
sPrice = (uPrice*(1-(sPercent/100))).toFixed(2);
}
$('#salePrice').val(sPrice);
}
What im looking to achieve is have "SalePrice" update based on the "UnitPrice" and "SalePrice" entered. With my current code above, this is not happening. I get no response from the cakephp form field "SalePrice". Is this even possible?
Here is a jsfiddle of how i would like it to work
Im really sorry if this is a novice question, I am new to javascript.
Kind regards
Congratulations, it's already working! I tested the jsfiddle, and everything works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.