onchange不工作

时间:2015-08-08 06:58:27

标签: javascript php jquery html

我的网站中有以前的代码,使用单输入框加载不同的值。我在代码中有四种贷款类型

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 ..如何设置不同的输入框相同的值我用过旧网站

我的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 = "0123456789.-";
       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:  url

我的开发网站网址: my url

代码相同但功能不是新工作?关于它的任何想法?

3 个答案:

答案 0 :(得分:0)

onchange仅在控件模糊时触发。请尝试使用onkeypress

答案 1 :(得分:0)

你的名字与名称和id相冲突,只需给出另一个名字并尝试。

答案 2 :(得分:0)

<td>名称和ID名称是冲突,因此更改了它们并尝试