从javascript中的其他函数获取值并在另一个javascript函数中再次使用它们并将它们添加到一起以查找新结果

时间:2022-10-27 09:50:56
<!DOCTYPE html>

<html>

     <head>
          <title>Nitro Motorbike</title>
           <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
          <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
          <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
          <script src="SydCalculation.js"></script>
          <script src="MelCalculation.js"></script>
          <script src="QLDCalculation.js"></script>
          <script src="PerthCalculation.js"></script>
          <script src="TotalSalesCalculation.js"></script>

          <meta name="viewport" content="initial-scale=1, maximum-scale=1">
     </head>

<body>

     <div data-role="page" data-title="Nitro Motorbike">
          <!-- Header-->
          <div data-role="header">
               <h1>Nitro Motorbike Total Sales Calculation Screen of All the Stores</h1>

             <input type="button" value="Home" id="btnAdd" data-inline="true" data-icon="home" data-iconpos="right" 
           onclick="window.location.href='file:///F:/programming%20business%20apps/Assignment/Nitro%20Motorbikemain%20page%20JQuery.html'"> 
           </div>

          <!-- Main-->
          <div data-role="main" class="ui-content">


 &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp
 &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp
 &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp &nbsp
 &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp
 &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp &nbsp
 &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp
 &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp &nbsp


 <img id="Bike"  src="bike8.jpg" height="500" width="1000" align="center" />
               </div>

               <form name ="totalSaleForm" >
                    <div class="ui-field-contain">
                        <label for="txtTotalAmountSyd">Sales by Sydney Store (in $) </label><br>
                        <input type="text" name="txtTotalAmountSyd" id="txtTotalAmountSyd" Disabled> <br>
                        <label for="txtTotalAmountMel"> Sales by Melbourne Store (in $)</label><br>
                        <input type="text" name="txtTotalAmountMel" id="txtTotalAmountMel" Disabled><br>
                        <label for="txtTotalAmountQLD"> Sales by Queensland Store (in $)</label><br>
                        <input type="text" name="txtTotalAmountQLD" id="txtTotalAmountQLD" Disabled ><br>
                        <label for="txtTotalAmountPerth"> Sales by Perth Store (in $)</label><br>
                        <input type="text" name="txtTotalAmountPerth" id="txtTotalAmountPerth" Disabled><br>
                        <label for="txttotalGrossProfit"> Total Gross Profit (in $)</label><br>
                        <input type="text" name="txttotalGrossProfit" id="txttotalGrossProfit" Disabled><br>


            <input type="button" value="Calculate" id="btnAdd" data-inline="true" data-icon="check" data-iconpos="right" 
            onclick="Process()"> <br><br><br><br>

            <input type="button" value="Next"id="btnAdd" data-inline="true" data-icon="carat-r" data-iconpos="right" 
            onclick="window.location.href='file:///F:/programming%20business%20apps/Assignment/TotalNetProfitJquery.html'" /><br> <br>


 </form>
          </div>

          <!-- Footer -->
          <div data-role="footer">
               <h4>Copyright Nitro Motorbike</h4>
          </div>
     </div> 

</body> 
</html>

Following is my function that i have used for getting values from my previous javascript files but i am not sure if this is right or not.

以下是我的功能,我用来从我以前的JavaScript文件中获取值,但我不确定这是否正确。

function addTotalSalesDB() {
     var sql;

     sql = "INSERT INTO Widgets VALUES (";
     sql = sql + totalAmountSyd +", ";
     sql = sql + totalAmountMel + "', ";
     sql = sql + totalAmountQLD + ", ";
     sql = sql + totalAmountPerth + ")";

     db.transaction(function (tx) {
          tx.executeSql(sql);
     });

     PrepareForm();
}

function PrepareForm() {

     totalSaleForm.txtTotalAmountSyd.value = "";
     totalSaleForm.txtTotalAmountMel.value = "";
     totalSaleForm.txtTotalAmountQLD.value = "";
     totalSaleForm.txtTotalAmountPerth.value = "";

     totalSaleForm.txttotalGrossProfit.focus();
}


function Process() {


     totalAmountSyd = totalSaleForm.txtTotalAmountSyd.value;
     totalAmountMel= totalSaleForm.txtTotalAmountMel.value;
     totalAmountQLD =totalSaleForm.txtTotalAmountQLD.value;
     totalAmountPerth = totalSaleForm.txtTotalAmountPerth.value;

     txttotalGrossProfit.value= totalAmountSyd+totalAmountMel+totalAmountQLD+totalAmountPerth;
}

1 个解决方案

#1


0  

Use hidden fields with the values you want to pass to another function. You can set and retrieve values using jQuery, i.e.

使用隐藏字段以及要传递给另一个函数的值。您可以使用jQuery设置和检索值,即

var field1 = jQuery('#field1').val();

Then do what you need with field1

然后用field1做你需要的

#1


0  

Use hidden fields with the values you want to pass to another function. You can set and retrieve values using jQuery, i.e.

使用隐藏字段以及要传递给另一个函数的值。您可以使用jQuery设置和检索值,即

var field1 = jQuery('#field1').val();

Then do what you need with field1

然后用field1做你需要的