当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Updating cakephp form input with javascript

问题描述:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: