选择行值用于在java脚本中进行计算

时间:2015-09-18 13:05:06

标签: javascript jquery html mysql

我正在创建贷款利息计算项目。我的输入页面有很多有两个部分比较和主要部分。比较部分隐藏输入字段。

两个部分都有相同的值

主要部分有贷款类型单选按钮

比较部分有贷款类型下拉框

我的问题比较框工作完全所有贷款。当选择主要贷款类型时,如果选择两个相同的值,则其工作正常

我的主要贷款部分图片

enter image description here

我的比较贷款部分值图像enter image description here

如果用户选择值比较部分工作它不工作单选按钮

/*state holders*/
/*WARNING!! this script must be above all other js scripts*/

var userChangedUpfrontMIPPc_ = false;
var userChangedUpfrontMIPAmt_ = false;
var userChangedMonthlyMIP_ = false;
var userChangedDownPaymentPc_ = false;
var userChangedDownPaymentAmt_ = false;
userChangedUpfrontMIP = false;
userChangedMonthlyMIP = false;
userChangedSSMonthlyMIP = false;

//state=true or false
function userChangedUpfrontMIPPc(state) {
  userChangedUpfrontMIPPc_ = state;
}
//state=true or false
function userChangedUpfrontMIPAmt(state) {
  userChangedUpfrontAmt_ = state;
}
//state=true or false
function userChangedMonthlyMIP(state) {
  userChangedUpfrontMIP_ = state;
}
//state=true or false
function userChangedDownPaymentPc(state) {
  userChangedDownPaymentPc_ = state;
}
//state=true or false
function userChangedDownPaymentAmt(state) {
  userChangedDownPaymentAmt_ = state;
}

function getMIP(str) {
  //get user input
  ficorange = document.forms['frmCalculator'].elements['ficorange'].value;
  compareloan = document.forms['frmCalculator'].elements['ddlCompare1'].value;
  loantype = document.forms['frmCalculator'].elements['loantype'].value;
  purchaseprice = document.forms['frmCalculator'].elements['purchaseprice'].value;

  downpaymentamt = "";

  for (i = 0; i < 4; i++) {
    if (document.forms['frmCalculator'].elements['loantype'][i].checked == true) {
      loantype = document.forms['frmCalculator'].elements.loantype[i].value;
    }
  }

  // alert(str);
  // if(str== "Compare")
  // {   if(loantype=="jumbo")
  // {
  // downpaymentpc=document.getElementById("downpaymentConv").value;
  // document.getElementById("upfrontMIPPc1").value;
  // document.getElementById("monthlyMIPPc1").value;
  // document.getElementById("ssmonthlyMIPPc1").value;
  // }  
  // }

  if (loantype == "jumbo") {
    downpaymentpc = document.getElementById("downpaymentConv").value;
    interestrate = document.getElementById("interestrate1").value;
  }
  if (loantype == "fha") {
    downpaymentpc = document.getElementById("downpaymentFHA").value;
    interestrate = document.getElementById("interestrateCompare").value;

  }
  if (loantype == "va") {
    downpaymentpc = document.getElementById("downpaymentVA").value;
    interestrate = document.getElementById("interestrate3").value;
  }
  if (loantype == "usda") {
    downpaymentpc = document.getElementById("downpaymentUSDA").value;
    interestrate = document.getElementById("interestrate4").value;
  }
  //seconds and silent seconds
  totalseconds_ = 0.0;
  totalsilentseconds_ = 0.0;
  secondV = document.forms['frmCalculator'].elements['second'].value;
  if (secondV == "") {
    secondV = "0";
  }
  secondV_ = parseFloat(secondV);
  secondT = document.forms['frmCalculator'].elements['secondtype'].value;
  if (secondT == "normal") {
    totalseconds_ += secondV_;
  } else {
    totalsilentseconds_ += secondV_;
  }

  thirdV = document.forms['frmCalculator'].elements['third'].value;
  if (thirdV == "") {
    thirdV = "0";
  }
  thirdV_ = parseFloat(thirdV);
  thirdT = document.forms['frmCalculator'].elements['thirdtype'].value;
  if (thirdT == "normal") {
    totalseconds_ += thirdV_;
  } else {
    totalsilentseconds_ += thirdV_;
  }

  fourthV = document.forms['frmCalculator'].elements['fourth'].value;
  fourthT = document.forms['frmCalculator'].elements['fourthtype'].value;
  if (fourthV == "") {
    fourthV = "0";
  }
  fourthV_ = parseFloat(fourthV);
  if (fourthT == "normal") {
    totalseconds_ += fourthV_;
  } else {
    totalsilentseconds_ += fourthV_;
  }

  fifthV = document.forms['frmCalculator'].elements['fifth'].value;
  fifthT = document.forms['frmCalculator'].elements['fifthtype'].value;
  if (fifthV == "") {
    fifthV = "0";
  }
  fifthV_ = parseFloat(fifthV);
  if (fifthT == "normal") {
    totalseconds_ += fifthV_;
  } else {
    totalsilentseconds_ += fifthV_;
  }

  sixthV = document.forms['frmCalculator'].elements['sixth'].value;
  sixthT = document.forms['frmCalculator'].elements['sixthtype'].value;
  if (sixthV == "") {
    sixthV = "0";
  }
  sixthV_ = parseFloat(sixthV);
  if (sixthT == "normal") {
    totalseconds_ += sixthV_;
  } else {
    totalsilentseconds_ += sixthV_;
  }

  q = "ficorange=" + ficorange;
  q += "&loantype=" + loantype;
  q += "&purchaseprice=" + purchaseprice;
  q += "&downpaymentpc=" + downpaymentpc;
  q += "&downpaymentamt=" + downpaymentamt;
  q += "&seconds=" + totalseconds_;
  q += "&silentseconds=" + totalsilentseconds_;

  if (loantype == "" || purchaseprice == "" || (downpaymentpc == "" && downpaymentamt == "")) {
    //document.getElementById("txtHint").innerHTML= "";
    return;
  }
  if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp = new XMLHttpRequest();
  }
  else {
    //code for IE6, IE5
    xlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange = function () {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
      //alert (xmlhttp.responseText);
      var values = xmlhttp.responseText.split(",");
      if (str = "loantype") {
        if (userChangedUpfrontMIP == false) {
          if (loantype == "jumbo") {
            document.getElementById("upfrontMIPPc1").value = values[0];
            document.getElementById("monthlyMIPPc1").value = values[2];
            document.getElementById("ssmonthlyMIPPc1").value = values[6];
            // document.forms["frmCalculator"].elements["upfrontmipamt"].value="";  
            // document.forms["frmCalculator"].elements["monthlymipamt"].value="";      
            // document.forms["frmCalculator"].elements["ssmonthlymipamt"].value="";                
            //$('#monthlyMIPPc2').val(str);
          }
          if (loantype == "fha") {
            document.getElementById("upfrontMIPPc2").value = values[0];
            document.getElementById("monthlyMIPPc2").value = values[2];
            document.getElementById("ssmonthlyMIPPc2").value = values[6];
            // document.forms["frmCalculator"].elements["upfrontmipamt"].value="";  
            // document.forms["frmCalculator"].elements["monthlymipamt"].value="";      
            // document.forms["frmCalculator"].elements["ssmonthlymipamt"].value="";    
            //$('#monthlyMIPPc2').val(str);
          }
          if (loantype == "va") {
            document.getElementById("upfrontMIPPc3").value = values[0];
            document.getElementById("monthlyMIPPc3").value = values[2];
            document.getElementById("ssmonthlyMIPPc3").value = values[6];
            // document.forms["frmCalculator"].elements["upfrontmipamt"].value="";  
            // document.forms["frmCalculator"].elements["monthlymipamt"].value="";      
            // document.forms["frmCalculator"].elements["ssmonthlymipamt"].value="";    
            //$('#monthlyMIPPc2').val(str);
          }
          if (loantype == "usda") {
            document.getElementById("upfrontMIPPc4").value = values[0];
            document.getElementById("monthlyMIPPc4").value = values[2];
            document.getElementById("ssmonthlyMIPPc4").value = values[6];
            //$('#monthlyMIPPc2').val(str);
          }
        }
      }
      else {
        document.forms["frmCalculator"].elements["upfrontmippc2"].value = values[0];
        document.forms["frmCalculator"].elements["upfrontmipamt"].value = "";
        document.forms["frmCalculator"].elements["monthlymippc2"].value = values[2];
        document.forms["frmCalculator"].elements["monthlymipamt"].value = "";
        document.forms["frmCalculator"].elements["ssmonthlymippc2"].value = values[6];
        document.forms["frmCalculator"].elements["ssmonthlymipamt"].value = "";
      }
    }
    if (compareloan == "jumbo") {
      a = document.getElementById("downpaymentConv").value;
      document.getElementById("downpaymentCompare").value = a;
      b = document.getElementById("upfrontMIPPc1").value;
      document.getElementById("CompareUpfront").value = b;
      c = document.getElementById("monthlyMIPPc1").value;
      document.getElementById("CompareMonthly").value = c;
      d = document.getElementById("ssmonthlyMIPPc1").value;
      document.getElementById("ComparessMonthly").value = d;
      e = document.getElementById("interestrate1").value;
      document.getElementById("interestrateCompare").value = e;
    }
    if (compareloan == "fha") {
      a = document.getElementById("downpaymentFHA").value;
      document.getElementById("downpaymentCompare").value = a;
      b = document.getElementById("upfrontMIPPc2").value;
      document.getElementById("CompareUpfront").value = b;
      c = document.getElementById("monthlyMIPPc2").value;
      document.getElementById("CompareMonthly").value = c;
      d = document.getElementById("ssmonthlyMIPPc2").value;
      document.getElementById("ComparessMonthly").value = d;
    }
    if (compareloan == "va") {
      a = document.getElementById("downpaymentVA").value;
      document.getElementById("downpaymentCompare").value = a;
      b = document.getElementById("upfrontMIPPc3").value;
      document.getElementById("CompareUpfront").value = b;
      c = document.getElementById("monthlyMIPPc3").value;
      document.getElementById("CompareMonthly").value = c;
      d = document.getElementById("ssmonthlyMIPPc3").value;
      document.getElementById("ComparessMonthly").value = d;
    }
    if (compareloan == "usda") {
      alert(compareloan);
      a = document.getElementById("downpaymentUSDA").value;
      document.getElementById("downpaymentCompare").value = a;
      b = document.getElementById("upfrontMIPPc4").value;
      document.getElementById("CompareUpfront").value = b;
      c = document.getElementById("monthlyMIPPc4").value;
      document.getElementById("CompareMonthly").value = c;
      d = document.getElementById("ssmonthlyMIPPc4").value;
      document.getElementById("ComparessMonthly").value = d;
    }
  }
  xmlhttp.open("GET", "getMIPs.php?" + q, true);
  //alert(q);
  xmlhttp.send();
}

这个我的脚本我正在使用函数变量比较贷款=比较贷款 主要贷款类型= loantype其仅工作comapre部分。同时主要部分工作时,两个部分选择相同的值。请在我的剧本中有任何错误..提前谢谢。如果用户选择单选按钮值,则选择Row of value ..

0 个答案:

没有答案