真的,我会疯狂地修复我的Javascript计算工具。我需要你的帮助。当我使用递增/递减或者手动输入值第1层和第2层字段时,它显示的值不正确。
请帮我解决一下,或者给我正确的解决方案以解决问题。
我的实时工具在这里:http://propertyjungle.com.au/tools.php。问题出在 “销售时的分层代理成本” 部分。
在我设置的这个工具中,
House Sale Price = $20,000
then other fees = $10,000
then tier 1 % = 0.1%
then tier 1 $ = $10,000
then tier 2 % = 0.1%
使用上面的数据显示我正确的值,但是当我输入以下数据时,它显示我错误的代理费用。
increase tier 1$ ('tier 1$' is field name)
then increase tier 2% ('tier 2%' is field name)
then repeat
这就是问题所在。这似乎是更新代理费用的延迟。
这是Javascript和HTML代码。
<script>
jQuery(document).ready(function(){
$('#pvaluea').change(function(){
var pi_value = $('#pvaluec').val() * $('#pvalueb').val() / 100;
var pi_valueb = $('#pvaluea').val() - $('#pvaluec').val();
var pi_valuec = pi_valueb * $('#pvalued').val() / 100;
var pi_valued = pi_value + pi_valuec;
//$('#pvaluee').val(pi_valued);
var pi_valuee = $('#pvaluec').val() * 0.1 / 100;
$('#pvaluef').val(pi_valuee);
var pi_valuef = $('#pvaluea').val() - $('#pvaluec').val();
var pi_valueg = pi_valuef * $('#pvalued').val() / 100;
$('#pvalueg').val(pi_valueg);
});
$('#pvalueb').change(function(){
var pi_value = $('#pvaluec').val() * $('#pvalueb').val() / 100;
var pi_valueb = $('#pvaluea').val() - $('#pvaluec').val();
var pi_valuec = pi_valueb * $('#pvalued').val() / 100;
var pi_valued = pi_value + pi_valuec;
$('#pvaluee').val(pi_valued);
var otherFees2 = parseFloat(document.getElementById('otherFees2').value);
var otherFees2 = otherFees2 + pi_valued;
$('#myTotal2').val(otherFees2);
var pi_valuee = $('#pvaluec').val() * 0.1 / 100;
$('#pvaluef').val(pi_valuee);
var pi_valuef = $('#pvaluea').val() - $('#pvaluec').val();
var pi_valueg = pi_valuef * 0.1 / 100;
$('#pvalueg').val(pi_valueg);
});
$('#pvaluec').change(function(){
var pi_value = $('#pvaluec').val() * $('#pvalueb').val() / 100;
var pi_valueb = $('#pvaluea').val() - $('#pvaluec').val();
var pi_valuec = pi_valueb * $('#pvalued').val() / 100;
var pi_valued = pi_value + pi_valuec;
//$('#pvaluee').val(pi_valued);
<!-------- my code- ----->
var otherFees2 = parseFloat(document.getElementById('otherFees2').value);
var otherFees2 = otherFees2 + pi_valued;
$('#myTotal2').val(otherFees2);
<!---- my code end ------ >
var pi_valuee = $('#pvaluec').val() * 0.1 / 100;
$('#pvaluef').val(pi_valuee);
var pi_valuef = $('#pvaluea').val() - $('#pvaluec').val();
var pi_valueg = pi_valuef * 0.1 / 100;
$('#pvalueg').val(pi_valueg);
});
$('#pvalued').change(function(){
var pi_value = $('#pvaluec').val() * $('#pvalueb').val() / 100;
var pi_valueb = $('#pvaluea').val() - $('#pvaluec').val();
var pi_valuec = pi_valueb * $('#pvalued').val() / 100;
var pi_valued = pi_value + pi_valuec;
$('#pvaluee').val(pi_valued);
<!-------- my code- ----->
var otherFees2 = parseFloat(document.getElementById('otherFees2').value);
var otherFees2 = otherFees2 + pi_valued;
$('#myTotal2').val(otherFees2);
<!---- my code end ------ >
var pi_valuee = $('#pvaluec').val() * 0.1 / 100;
$('#pvaluef').val(pi_valuee);
var pi_valuef = $('#pvaluea').val() - $('#pvaluec').val();
var pi_valueg = pi_valuef * 0.1 / 100;
$('#pvalueg').val(pi_valueg);
});
$('#otherFees2').change(function(){
var pi_valuee = $('#pvaluec').val() * 0.1 / 100;
var pi_valued = $('#pvaluea').val() * 0.1 / 100;
<!-------- my code- ----->
var otherFees2 = parseFloat(document.getElementById('otherFees2').value);
var otherFees2 = otherFees2 + pi_valuee + pi_valued;
$('#myTotal2').val(otherFees2);
<!---- my code end ------ >
});
});
function incrementValue2()
{
var value = parseInt(document.getElementById('pvaluea').value, 10);
value = isNaN(value) ? 0 : value;
value +=10000
document.getElementById('pvaluea').value = value;
$('#pvaluea').trigger("change");
}
function decrementValue2()
{
var value = parseInt(document.getElementById('pvaluea').value, 10);
value = isNaN(value) ? 0 : value;
value -=10000
document.getElementById('pvaluea').value = value;
$('#pvaluea').trigger("change");
}
function incrementValuec()
{
var value = parseInt(document.getElementById('pvaluec').value, 10);
value = isNaN(value) ? 0 : value;
value +=10000
document.getElementById('pvaluec').value = value;
$('#pvaluec').trigger("change");
}
function decrementValuec()
{
var value = parseInt(document.getElementById('pvaluec').value, 10);
value = isNaN(value) ? 0 : value;
value -=10000
document.getElementById('pvaluec').value = value;
$('#pvaluec').trigger("change");
}
function incrementValueO2()
{
var value = parseInt(document.getElementById('otherFees2').value, 10);
value = isNaN(value) ? 0 : value;
value +=10000
document.getElementById('otherFees2').value = value;
$('#pvaluec').trigger("change");
<!-- $('#pvalue1').trigger("change");-->
}
function decrementValueO2()
{
var value = parseInt(document.getElementById('otherFees2').value, 10);
value = isNaN(value) ? 0 : value;
value -=10000
document.getElementById('otherFees2').value = value;
$('#pvaluec').trigger("change");
}
function toggleIncrement2()
{
var value = parseFloat(document.getElementById('pvalueb').value, 10);
value = isNaN(value) ? 0 : value;
value +=0.1
value = parseFloat(value).toFixed(2)
document.getElementById('pvalueb').value = value;
$('#pvaluec').trigger("change");
}
function toggleDecrement2()
{
var value = parseFloat(document.getElementById('pvalueb').value, 10);
value = isNaN(value) ? 0 : value;
value -=0.1
value = parseFloat(value).toFixed(2)
document.getElementById('pvalueb').value = value;
$('#pvaluec').trigger("change");
}
function toggleIncrementd()
{
var value = parseFloat(document.getElementById('pvalued').value, 10);
value = isNaN(value) ? 0 : value;
value +=0.1
value = parseFloat(value).toFixed(2)
document.getElementById('pvalued').value = value;
$('#pvalued').trigger("change");
}
function toggleDecrementd()
{
var value = parseFloat(document.getElementById('pvalued').value, 10);
value = isNaN(value) ? 0 : value;
value -=0.1
value = parseFloat(value).toFixed(2)
document.getElementById('pvalued').value = value;
$('#pvalued').trigger("change");
}
</script>
<form name="tools2" onKeyUp="return validateForm2();" >
<table border="0" cellspacing="0" cellpadding="5">
<tr>
<td>House Sale Price:</td>
<td>$</td>
<td><input class="form-control" onkeypress="validate(event)" name="pvaluea" value="" placeholder=" Enter Sale Price" style="width:140px;" type="text" value="<?=$pvaluea?>" id="pvaluea" size="40" required </td>
<td align="left"><input type="button" onClick="incrementValue2()" value="+" /><input type="button" onClick="decrementValue2()" value="-" /> </td>
<td></td>
</tr>
<tr>
<td>Other Fees</td>
<td>$</td>
<td><input name="otherFees2" class="form-control" onkeypress="validate(event)" placeholder="Other Fees" type="number" value="<?=$pvalue1?>" style="width:140px;" id="otherFees2" required ></td>
<td align="left"><input type="button" onClick="incrementValueO2()" value="+" /><input type="button" onClick="decrementValueO2()" value="-" /> </td>
<td></td>
</tr>
<tr>
<td>Tier 1:</td>
<td>%</td>
<td><input onkeypress="validate(event)" class="form-control" name="pvalueb" value="" placeholder=" X% up to " style="width:140px;" type="text" value="<?=$pvalueb?>" id="pvalueb" size="40" class="required inputfield2" required >
</td>
<td><input type="button" onClick="toggleIncrement2()" value="+" /><input type="button" onClick="toggleDecrement2()" value="-" /></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td>$</td>
<td><input class="form-control" onkeypress="validate(event)" name="pvaluec" value="" placeholder="$Y of sale price" style="width:140px;" type="text" value="<?=$pvaluec?>" id="pvaluec" size="40" required ></td>
<td><input type="button" onClick="incrementValuec()" value="+" /><input type="button" onClick="decrementValuec()" value="-" /></td>
</tr>
</tr>
<tr>
<td>Tier 2:</td>
<td>%</td>
<td><input class="form-control" onkeypress="validate(event)" name="pvalued" value="" placeholder=" Y% above" style="width:140px;" type="text" value="<?=$pvalued?>" id="pvalued" size="40" required ></td>
<td><input type="button" onClick="toggleIncrementd()" value="+" /><input type="button" onClick="toggleDecrementd()" value="-" /></td>
<td> </td>
</tr>
<tr>
<td colspan="5"><input name="doRegister" class="btn btn-primary" type="submit" id="doRegister" value="Calculate" ></td>
</tr>
</table>
</form>
<h2>Results</h2>
<table>
<tr>
<td>Agent Fees:</td>
<td>$</td>
<td><input name="pvaluee" onkeypress="validate(event)" class="form-control" value="0" placeholder="" type="text" id="pvaluee" size="10" ></td></tr>
<tr>
<tr>
<td>Total Fees</td>
<td>$</td>
<td><input name="myTotal" onkeypress="validate(event)" class="form-control" placeholder="Total fees" type="number" value="" id="myTotal2" size="10"></td>
</tr>
<tr>
<td>Reducing the rate the agent is charging by 0.1% of the second tier will save you:</td>
<td>$</td>
<td><input onkeypress="validate(event)" class="form-control" name="pvaluef" value="0" placeholder="" type="text" id="pvaluef" size="10"></td>
</tr>
<tr>
<td>Reducing the rate the agent is charging by 0.1% of the first tier will save you:</td>
<td> $</td>
<td><input onkeypress="validate(event)" class="form-control" name="pvalueg" value="0" placeholder="" type="text" id="pvalueg" size="10" ></td>
</tr>
</table>
更新
计算公式:
If (Sale price - (sale price - tier1$)) is equal to or less than 0 then
tier 1 fee = ((sale price - (sale price - tier1))*tier1%)
If (Sale price - (sale price - tier1$)) is greater than 0,
then tier 1 fee = sale price & tier1%
Total agent fee = tier 1 fee + tier 2 fee
Total fee = total agent fee + other fee