2015-08-08 110 views
2

我在我的站點中有以前的代碼在單個輸入框中使用不同的值加載。我在代碼onchange不能正常工作

1. Conv. 2.FHA 3.VA 4.USDA if click any loan change value 

首付輸入框的值值

<td>Down payment $</td> 
    <td> <input name="downpaymentpc" id="downpaymentpc" type="text" size="8" maxlength="8" onChange="javascript:downPaymentPcChanged(true);" value="<?php echo $min_fha_down_payment;?>" />%</td> 

現在我有另一四種貸款類型的所有貸款類型有四種下載支付輸入框?我有賦值四個輸入框中不能正常工作顯示默認值3.5..how設置不同的輸入框中輸入相同的值,我用我的舊網站

我的javascript代碼:

<script type="text/javascript"> 
    var min_jumbo_down_payment_1="<?php echo $min_jumbo_down_payment_1?>"; 
    var min_jumbo_down_payment_2="<?php echo $min_jumbo_down_payment_2?>"; 
    var min_fha_down_payment="<?php echo $min_fha_down_payment?>"; 
    var max_fha_loan="<?php echo $max_fha_loan?>"; 
    var max_va_loan="<?php echo $max_va_loan?>"; 


    function isNumeric(strString) 
     // check for valid numeric strings 
     { 

     var strValidChars = ".-"; 
     var strChar; 
     var blnResult = true; 

     if (strString.length == 0) return false; 

     // test strString consists of valid characters listed above 
     for (i = 0; i < strString.length && blnResult == true; i++) 
      { 
      strChar = strString.charAt(i); 
      if (strValidChars.indexOf(strChar) == -1) 
      { 
       blnResult = false; 
      } 
      } 
     return blnResult; 
     } 

    function ficoChanged() 
    { 
     //setDownPayment(); 

     getMIP("hh"); 

    } 

    function loanTypeChanged() 
    { 

     setDownPayment(); 
     getMIP("loantype"); //it must be set to loantype 
    alert(loantype); 
    } 

    //always called by either change in loantype or change in fico 
    function setDownPayment() 
    { 

     if (userChangedDownPaymentPc_==true || userChangedDownPaymentAmt_==true) 
     { 
      return; 
     } 
     //1. get selected loan type 
     for (i=0;i<4;i++) 
     { 
      if (document.forms['frmCalculator'].elements['loantype'][i].checked==true) 
      { 
       var loantype_=document.forms['frmCalculator'].elements.loantype[i].value; 
       break; 
      } 
     } 

     if (loantype_=="usda" || loantype_=="va") 
     { 
      document.forms['frmCalculator'].elements.downpaymentpc.value=0; 
     }  
     else if (loantype_=="fha") 
     { 
      document.forms['frmCalculator'].elements.downpaymentpc.value=min_fha_down_payment; 
     } 
     else if (loantype_=="jumbo") 
     { 
      var ficorange_=document.forms['frmCalculator'].elements['ficorange'].value; 
      var arr=ficorange_.split("-"); 
      if(arr[1] >= 720) 
      document.forms['frmCalculator'].elements.downpaymentpc.value=min_jumbo_down_payment_1; 
      else 
      document.forms['frmCalculator'].elements.downpaymentpc.value=min_jumbo_down_payment_2; 
     } 
    } 


     function purchasePriceAmountChanged(fromuser_) 
     { 
      getMIP("hh"); 
      document.forms['frmCalculator'].elements.monthlypayment.value=""; 
     } 

     function monthlyPaymentChanged(fromuser_) 
     { 

      document.forms['frmCalculator'].elements.purchaseprice.value=""; 
      document.forms['frmCalculator'].elements.upfrontmippc.value=""; 
      document.forms['frmCalculator'].elements.upfrontmipamt.value=""; 
      document.forms['frmCalculator'].elements.monthlymippc.value=""; 
      document.forms['frmCalculator'].elements.monthlymipamt.value=""; 
      document.forms['frmCalculator'].elements.ssmonthlymippc.value=""; 
      document.forms['frmCalculator'].elements.ssmonthlymipamt.value=""; 

     } 

     function downPaymentAmountChanged(fromuser_)//true (if user changed it) or false 
     { 
      alert("ok"); 
     if (document.forms['frmCalculator'].elements.downpaymentamt.value!="") 
     { 
     document.forms['frmCalculator'].elements.downpaymentpc.value="";   
     getMIP("hh"); 
     } 
     } 

     function downPaymentPcChanged(fromuser_)//true (if user changed it) or false 
     { 

     alert("ok 1"); 
     if (document.forms['frmCalculator'].elements.downpaymentpc.value!="") 
     { 
      alert("ok 2"); 
     document.forms['frmCalculator'].elements.downpaymentamt.value="";   
     getMIP("hh"); 

     } 
     } 

    // todo : CHANGE IT, ITS NOT WORKING ANYMORE 
     function getLoanAmount() 
     { 
     var purchaseprice_=0; 
     var downpayment_=0; 
     var loanamount_=-1; 
     var hasloan=false; 
     if(document.forms['frmCalculator'].elements.downpaymentamt.value!="") 
      { 
      downpayment_=document.forms['frmCalculator'].elements.downpaymentamt.value; 
      } 
     else 
      { 
       hasloan=true; 
      } 
     if (document.forms['frmCalculator'].elements.purchaseprice.value!="") 
      { 
      purchaseprice_=document.forms['frmCalculator'].elements.purchaseprice.value; 
      } 
     else 
      { 
      hasloan=true; 
      } 

     if (hasloan==false) 
      { 
      loanamount_= purchaseprice_ - downpayment_ ; 
      } 

      return loanamount_; 
     } 


     function getPurchasePrice() 
     { 
     if (document.forms['frmCalculator'].elements.purchaseprice.value!="") 
      { 
      purchaseprice_=document.forms['frmCalculator'].elements.purchaseprice.value; 
      } 
      else 
      { 
      purchaseprice_=-1; 
      } 
     return purchaseprice_; 
     } 

     function upfrontMIPPcChanged(fromuser_)//true (if user changed it) else false 
     { 

      alert("ok"); 
     userChangedUpfrontMIP=fromuser_; 
     if (document.forms['frmCalculator'].elements.upfrontmippc.value !="") 
      { 
      document.forms['frmCalculator'].elements.upfrontmipamt.value=""; 
      } 
     } 

     function upfrontMIPAmountChanged(fromuser_)//true (if user changed it) or false 
     { 
     userChangedUpfrontMIP=fromuser_; 
     if (document.forms['frmCalculator'].elements.upfrontmipamt.value !="") 
      { 
      document.forms['frmCalculator'].elements.upfrontmippc.value=""; 
      } 
     } 

     function monthlyMIPPcChanged(fromuser_)//true (if user changed it) else false 
     { 
     userChangedMonthlyMIP=fromuser_; 
     if (document.forms['frmCalculator'].elements.monthlymippc.value !="") 
      { 
      document.forms['frmCalculator'].elements.monthlymipamt.value=""; 
      } 
     } 

     function monthlyMIPAmountChanged(fromuser_)//true (if user changed it) or false 
     { 
     userChangedMonthlyMIP=fromuser_; 
     if (document.forms['frmCalculator'].elements.monthlymipamt.value !="") 
      { 
      document.forms['frmCalculator'].elements.monthlymippc.value=""; 
      } 
     } 

     function ssmonthlyMIPPcChanged(fromuser_)//true (if user changed it) else false 
     { 
     userChangedSSMonthlyMIP=fromuser_; 
     if (document.forms['frmCalculator'].elements.ssmonthlymippc.value !="") 
      { 
      document.forms['frmCalculator'].elements.ssmonthlymipamt.value=""; 
      } 
     } 

     function ssmonthlyMIPAmountChanged(fromuser_)//true (if user changed it) or false 
     { 
     userChangedSSMonthlyMIP=fromuser_; 
     if (document.forms['frmCalculator'].elements.ssmonthlymipamt.value !="") 
      { 
      document.forms['frmCalculator'].elements.ssmonthlymippc.value=""; 
      } 
     } 

    function propertyTaxPcChanged(fromuser_)//true (if user changed it) or false 
     { 
     if (document.forms['frmCalculator'].elements.propertytaxpc.value!="") 
     { 
     document.forms['frmCalculator'].elements.propertytaxamt.value=""; 
     } 
     } 


    function propertyTaxAmountChanged(fromuser_)//true (if user changed it) or false 
     { 
     if (document.forms['frmCalculator'].elements.propertytaxamt.value!="") 
     { 
     document.forms['frmCalculator'].elements.propertytaxpc.value=""; 
     } 
     } 

    function hazardInsurancePcChanged(fromuser_)//true (if user changed it) or false 
     { 
     if (document.forms['frmCalculator'].elements.hazardinsurancepc.value!="") 
     { 
     document.forms['frmCalculator'].elements.hazardinsuranceamt.value=""; 
     } 
     } 

    function hazardInsuranceAmountChanged(fromuser_)//true (if user changed it) or false 
     { 
     if (document.forms['frmCalculator'].elements.hazardinsuranceamt.value!="") 
     { 
     document.forms['frmCalculator'].elements.hazardinsurancepc.value=""; 
     } 
     } 

    function melloRoosAmountChanged(fromuser_)//true (if user changed it) or false 
     { 
     if (document.forms['frmCalculator'].elements.melloroosfeeamt.value!="") 
     { 
     document.forms['frmCalculator'].elements.melloroosfeepc.value=""; 
     } 
     } 

    function melloRoosPcChanged(fromuser_)//true (if user changed it) or false 
     { 
     if (document.forms['frmCalculator'].elements.melloroosfeepc.value!="") 
     { 
     document.forms['frmCalculator'].elements.melloroosfeeamt.value=""; 
     } 
     }  

    function other1PcChanged(fromuser_)//true (if user changed it) or false 
     { 
     if (document.forms['frmCalculator'].elements.other1pc.value!="") 
     { 
     document.forms['frmCalculator'].elements.other1amt.value=""; 
     } 
     } 

    function other1AmountChanged(fromuser_)//true (if user changed it) or false 
     { 
     if (document.forms['frmCalculator'].elements.other1amt.value!="") 
     { 
     document.forms['frmCalculator'].elements.other1pc.value=""; 
     } 
     }  

    function other2PcChanged(fromuser_)//true (if user changed it) or false 
     { 
     if (document.forms['frmCalculator'].elements.other2pc.value!="") 
     { 
     document.forms['frmCalculator'].elements.other2amt.value=""; 
     } 
     } 

    function other2AmountChanged(fromuser_)//true (if user changed it) or false 
     { 
     if (document.forms['frmCalculator'].elements.other2amt.value!="") 
     { 
     document.forms['frmCalculator'].elements.other2pc.value=""; 
     } 
     } 

    function other3PcChanged(fromuser_)//true (if user changed it) or false 
     { 
     if (document.forms['frmCalculator'].elements.other3pc.value!="") 
     { 
     document.forms['frmCalculator'].elements.other3amt.value=""; 
     } 
     } 

    function other3AmountChanged(fromuser_)//true (if user changed it) or false 
     { 
     if (document.forms['frmCalculator'].elements.other3amt.value!="") 
     { 
     document.forms['frmCalculator'].elements.other3pc.value=""; 
     } 
     } 

     function secondsChanged() 
     { 
     getMIP("hh"); 
     } 

下面的代碼工作正常網站網址: url

我開發的網站網址: my url

代碼是相同的,但功能不工作新的?有關它的任何想法?

+0

您必須設置該元素的名稱和ID! – Samane

+0

根據Samane的說法,當你訪問像這樣的元素 'downpaymentamt = document.forms ['frmCalculator']。elements ['downpaymentamt'] value;' 文本'downpayment'實際上是指'name'的元素,而不是id。由於元素'」名稱爲「downpaymentpc」,而不是「downpayment」,嘗試獲取值失敗。你的調試器會告訴你,熟悉它。 – enhzflep

+0

我已經爲每個輸入字段設置了每個名稱和我的名字? @Samane –

回答

0

onchange只在控件模糊時觸發。嘗試onkeypress而不是

0

你的名字與名稱和身份證號碼衝突,只是給另一個名字和嘗試。

0

<td>名和ID名稱的衝突,所以改變了他們,並嘗試