我无法从网页上的隐藏框中获取数据

时间:2016-04-14 08:04:06

标签: javascript php jquery html

我想在用户点击其他时显示隐藏的框。我想从文本框中获取利率并执行与给定的其他利率一样的计算。有任何想法吗?这是我的代码。谢谢

<html>
    <head>
        <meta charset="UTF-8">
        <title>Mortgage Calculator</title>
          <link rel="stylesheet" type="text/css" href="main.css" />

    </head>
    <body>

    <main>

        <h1>
          Mortgage Calculator  
        </h1>


  <script language="JavaScript" type="text/javascript">
<!--
function getOther(sel,fld){
    fld.style.display = (sel.selectedIndex===sel.options.length-1)?"inline":"none";
}
window.onload = function() {
    document.getElementById("Other").style.display = "none";
    document.getElementById("othLabel").style.display = "none";
}
//-->
</script>


<form action="Display.php" method = "POST">
  Price Of Home: <input type="text" name="PriceOfHome"><br></br>
  Down Payment: <input type="text" name="DownPayment"><br>

  <p> Duration Of Loan</p>
<input type="radio" name="DurationOfLoan" value="10 years"> 10 Years<br>
<input type="radio" name="DurationOfLoan" value="20 years"> 20 Years <br>
<input type="radio" name="DurationOfLoan" value="30 years"checked> 30 Years </br>


<br>
 <label for="Interest Rate">Interest Rate:</label>
<select name="InterestRate" onchange="getOther(this.form.Other);">

 <option value="4">4%</option>
 <option value="4.75">4.75%</option>
 <option value="5">5%</option>
 <option value="9">9%</option>
  <option value="10">10%</option>
 <option value="Other">Other</option>

 <option value="InterestRate" selected>4.5%</option>


 <input type="hidden" name="Other" value="<?php echo $var;?>" />
</select> 
 <label id="Other" for="Other">Other:</label><input type="text" name="Other" id="Other" style='display:none;'/>
 </br>

 <br></br>
 <button type="submit" value="Calculate">Calculate</button>
<button type="reset" value="Reset">Reset</button>

 <br></br>

</form>
        <?php
   //    $PriceOfHome = filter_input(INPUT_POST, 'PriceOfHome');
 //$DownPayment = filter_input(INPUT_POST, 'DownPayment');
// $action = filter_input(INPUT_POST, 'action');
          ?>
      </main>
    </body>

</html>


  <?php 

 //   $_POST['foo'];

 // get the data from the form
    $PriceOfHome = filter_input(INPUT_POST, 'PriceOfHome');
    $DownPayment = filter_input(INPUT_POST, 'DownPayment');
    $DurationOfLoan = filter_input(INPUT_POST, 'DurationOfLoan');
    // if ($DurationOfLoan == NULL) {
      //  $DurationOfLoan = 'invalid';
   // }

    $InterestRate = filter_input(INPUT_POST, 'InterestRate');
    $Other = filter_input(INPUT_POST, 'InterestRate');
    $TotalSimpleInterest = filter_input(INPUT_POST, 'Total Simple Interest');
    $TotalPriceOfHome = filter_input(INPUT_POST, 'Total Price Of Home');
    $MonthlyPayments = filter_input(INPUT_POST, 'Monthly Payments');



    // calculate the discount and discounted price
    //$InterestRate = ($InterestRate/100);
    $TotalSimpleInterest = $PriceOfHome - $DownPayment * ($InterestRate/100) *$DurationOfLoan;
    $TotalPriceOfHome = $PriceOfHome + $TotalSimpleInterest; 
    $MonthlyPayments =($TotalPriceOfHome/ $DurationOfLoan)/12;
   // $discount_price = $list_price - $discount;



 // apply currency formatting to the dollar and percent amounts
    $PriceOfHome = "$".number_format($PriceOfHome, 2);
    $DownPayment = "$".number_format($DownPayment, 2);
    $InterestRate = $InterestRate."%";
    $TotalSimpleInterest = "$".number_format( $TotalSimpleInterest, 2);
    $TotalPriceOfHome = "$".number_format( $TotalPriceOfHome, 2);
    $MonthlyPayments = "$".number_format( $MonthlyPayments, 2);






 ?>







<!DOCTYPE html>
<html>

<head>
    <title>Mortgage Calculator</title>
    <link rel="stylesheet" type="text/css" href="main.css">
</head>

<body>
    <main>
        <h1>Mortgage Calculator</h1>
        <br>  </br>
        <label>Price Of Home:</label>
        <span><?php echo ($PriceOfHome); ?></span>
        <br>  </br>

        <label>Down Payment:</label>
        <span><?php echo ($DownPayment); ?></span>
        <br>  </br>

        <label>Duration Of Loan:</label>
        <span><?php echo ($DurationOfLoan); ?></span>
          <br>  </br>

        <label>Interest Rate:</label>
        <span><?php echo ($InterestRate); ?></span>
         <br>  </br>

        <label>Total Simple Interest:</label>
        <span><?php echo ($TotalSimpleInterest); ?></span>
       <br>  </br>

        <label>Total Price Of Home:</label>
        <span><?php echo ($TotalPriceOfHome); ?></span>
       <br>  </br>

         <label>Monthly Payments:</label>
        <span><?php echo ($MonthlyPayments); ?></span>
       <br>  </br>

       <input type="hidden" name="Other" value="<?php echo $var;?>" />
    </main>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您无法从隐藏输入中获取值

你可以输入input = hidden

的类型
<input type="hidden" name="Other" id="Other">

<input type="text" name="Other" id="Other" style='opacity:0;position:absolute;'>