[英]How can I automatically calculate a payment on page load using javascript?
加载页面后,我想自动计算贷款付款。 对于付款计算,我具有javascript函数calculatePayment(field.form)
。
我有四个变量,可由用户更改。 默认情况下,我将使用当前帖子中的信息(例如汽车价格,5.5%的利息,5年,汽车价格的10%首付):
<p><label class="loan-title" for="l-amount"><?php _e('PRICE: '.$symbols['currency'].'','language')?></label>
<input type="text" size="10" name="price" value="<?php if ( $fields['price']){ echo $fields['price'];} else { echo '0'; };?>" class="l-inputbar" id="l-amount" onBlur="checkForZero(this)" onChange="checkForZero(this)"></p>
<p><label class="loan-title" for="l-down"><?php _e('DOWNPAYMENT: '.$symbols['currency'].'','language')?></label>
<input type="text" size="10" name="dp" id="l-down" class="l-inputbar" value="<?php if ( $fields['price']){ echo $fields['price']*0.1;} else { echo '0'; };?>" onChange="calculatePayment(this.form)"></p>
<p><label class="loan-title" for="l-amount"><?php _e('PROCENTU LIKME: %','language')?></label>
<input type="text" size="5" name="ir" value="5.5" class="l-inputbar" onBlur="checkForZero(this)" onChange="checkForZero(this)"> </p>
<p><label class="loan-title" for="l-amount"><?php _e('PERIOD: (years) ','language')?></label>
<input type="text" size="4" name="term" value="5" class="l-inputbar" onBlur="checkForZero(this)" onChange="checkForZero(this)"> </p>
<p class="calculate-wrapper"><input type="button" name="cmdCalc" value="" class="calculate-btn" onClick="cmdCalc_Click(this.form)" onLoad="calculatePayment(this.form)" ></p>
<p><label class="loan-title" for="l-amount"><?php _e('MONTHLY PAYMENT: '.$symbols['currency'].'','language')?></label>
<input type="label" size="12" class="l-inputbar" name="pmt"></p>
所有数据都加载到输入字段中,但是我找不到解决方案如何计算页面加载时的付款。 我已经尝试了所有的javascript函数调用。 似乎没有任何作用。
您可以使用jQuery的document.ready()或* $(function(){/ *您在这里的东西* /})*进行检查,以确定是否加载和渲染了文档。 它比window.onload复杂一些,所以我建议您使用框架(无论如何)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.