如何在total_cost_acquistion中使用在total_no_of_units和cost_per_unit中输入的值,即(总成本=单位*单位成本)请给我建议任何方法total_cost_acquistion的值必须在给出no_of_units和cost_per_units后立即显示...
<?php
require_once "session.php";
?>
<?php
include('connection.php');
if (isset($_POST['submit'])){
$sl_no =$_POST['sl_no'];
$dec =$_POST['description'];
$loctn =$_POST['location'];
$ref_no =$_POST['reference_no'];
$d_of_aqstn =$_POST['date_of_acquisation'];
$t_of_un =$_POST['total_no_of_units'];
$cst_p_un =$_POST['cost_per_unit'];
$tl_cost_aqstn =$_POST['total_cost_of_acquistion'];
$lf_ast_pr_cdl =$_POST['life_of_assets_per_codal'];
$no_yr_ast_use =$_POST['no_year_assets_use'];
$rt_deprtn =$_POST['rate_depreciation'];
$act_deprtn =$_POST['accumulate_depreciation'];
$val_as_on = $_POST['value_as_on'];
$remks =$_POST['remarks'];
$query = "insert into form(sl_no, description, location, reference_no, date_of_acquisation, total_no_of_units, cost_per_unit, total_cost_of_acquistion, life_of_assets_per_codal, no_year_assets_use, rate_depreciation, accumulate_depreciation, value_as_on, remarks)
values('$sl_no','$dec','$loctn','$ref_no','$d_of_aqstn','$t_of_un','$cst_p_un','$tl_cost_aqstn','$lf_ast_pr_cdl','$no_yr_ast_use','$rt_deprtn','$act_deprtn','$val_as_on','$remks')";
$retval = mysql_query($query,$con);
if(!$retval )
{
die('Could not enter data: ' . mysql_error());
}
mysql_close($con);
}
?>
<html>
<head>
<meta charset = "utf-8">
<link rel = "stylesheet"
href = "//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script type = "text/javascript"
src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type = "text/javascript"
src = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
<title>Add a Form</title>
</head>
<body>
<h1 align="center"><strong>FIXED ASSET REGISTER</strong></h1>
<b align="center">Welcome : <i><?php echo $_SESSION['login_user']; ?> </i></b>
<br>
<form method="POST" action="<?php $PHP_SELF ?>">
<div align="center">
<table width=100% cellpadding="5" cellspacing="2" align="center">
<tr>
<td colspan="2" align="center"> <h2><strong>FORM-10</strong></h2></td>
</tr>
<tr>
<td align="right"> <strong>Serial_No:</strong></td>
<td><input type="text" name="sl_no" placeholder="Serial_no" required></td>
</tr>
<tr>
<td align="right"> <strong>Description :</strong></td>
<td><input type="text" name="description" placeholder="description" required></td>
</tr>
<tr>
<td align="right"> <strong>Location:</strong></td>
<td><input type="text" name="location" placeholder="location" required></td>
</tr>
<tr>
<td align="right"> <strong>Reference_no:</strong></td>
<td><input type="text" name="reference_no" placeholder="reference_no" required></td>
</tr>
<tr>
<td align="right"> <strong>Date_of_Acquisition:</strong></td>
<td><input type="text" name="date_of_acquisation" id = "datepicker" placeholder="date_of_acquisation" required></td>
</tr>
<tr>
<td align="right"> <strong>Total_no_of_Units:</strong></td>
<td><input type="text" name="total_no_of_units" placeholder="total_no_of_units" required></td>
</tr>
<tr>
<td align="right"> <strong>Cost per Unit:</strong></td>
<td><input type="text" name="cost_per_unit" placeholder="cost_per_unit" required></td>
</tr>
<tr>
<td align="right"> <strong>Total Acquisition Cost:</strong></td>
<td><input type="text" name="total_cost_of_acquistion" placeholder="total_cost_of_acquistion" required></td>
</tr>
<tr>
<td align="right"> <strong>Asset Life:</strong></td>
<td><input type="text" name="life_of_assets_per_codal" placeholder="life_of_assets_per_codal" required></td>
</tr>
<tr>
<td align="right"> <strong>Years asset used:</strong></td>
<td><input type="text" name="no_year_assets_use" placeholder="no_of_year_assets_use" required></td>
</tr>
<tr>
<td align="right"> <strong>Depriciation Rate:</strong></td>
<td><input type="text" name="rate_depreciation" placeholder="rate_depreciation" required></td>
</tr>
<tr>
<td align="right"> <strong>Accumulated Depriciation:</strong></td>
<td><input type="text" name="accumulate_depreciation" placeholder="accumulate_depreciation_till_31/03/2016" required></td>
</tr>
<tr>
<td align="right"> <strong>Valuation:</strong></td>
<td><input type="text" name="value_as_on" placeholder="value_as_on_31/03/2016" required></td>
</tr>
<tr>
<td align="right"> <strong>Remarks:</strong></td>
<td><input type="text" name="remarks" placeholder="remarks" ></td>
</tr>
<!-- <tr>
<td align="right"> <strong>Status: </strong></td>
<td><select name="status" required>
<option></option>
<option>New</option>
<option>Old</option>
<option>Lost</option>
<option>Damage</option>
<option>Subject for Replacement</option>
<option>Archive</option>
</select>
</td>
</tr>-->
<tr>
<td colspan="2" align="center"><input type='submit' value=' Save ' name='submit'>
</tr>
</table>
<h4 align="right"><a href="mainpage1.php">BACK</a></h4>
</div>
</form>
</body>
</html>发布于 2017-06-17 00:02:53
我想这就是你想要的:
<?php
require_once "session.php";
?>
<?php
include('connection.php');
if (isset($_POST['submit'])){
$sl_no =$_POST['sl_no'];
$dec =$_POST['description'];
$loctn =$_POST['location'];
$ref_no =$_POST['reference_no'];
$d_of_aqstn =$_POST['date_of_acquisation'];
$t_of_un =$_POST['total_no_of_units'];
$cst_p_un =$_POST['cost_per_unit'];
$tl_cost_aqstn =$_POST['total_cost_of_acquistion'];
$lf_ast_pr_cdl =$_POST['life_of_assets_per_codal'];
$no_yr_ast_use =$_POST['no_year_assets_use'];
$rt_deprtn =$_POST['rate_depreciation'];
$act_deprtn =$_POST['accumulate_depreciation'];
$val_as_on = $_POST['value_as_on'];
$remks =$_POST['remarks'];
$query = "insert into form(sl_no, description, location, reference_no, date_of_acquisation, total_no_of_units, cost_per_unit, total_cost_of_acquistion, life_of_assets_per_codal, no_year_assets_use, rate_depreciation, accumulate_depreciation, value_as_on, remarks)
values('$sl_no','$dec','$loctn','$ref_no','$d_of_aqstn','$t_of_un','$cst_p_un','$tl_cost_aqstn','$lf_ast_pr_cdl','$no_yr_ast_use','$rt_deprtn','$act_deprtn','$val_as_on','$remks')";
$retval = mysql_query($query,$con);
if(!$retval )
{
die('Could not enter data: ' . mysql_error());
}
mysql_close($con);
}
?>
<html>
<head>
<meta charset = "utf-8">
<link rel = "stylesheet"
href = "//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script type = "text/javascript"
src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type = "text/javascript"
src = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
<title>Add a Form</title>
</head>
<body>
<h1 align="center"><strong>FIXED ASSET REGISTER</strong></h1>
<b align="center">Welcome : <i><?php echo $_SESSION['login_user']; ?> </i></b>
<br>
<form method="POST" action="<?php $PHP_SELF ?>">
<div align="center">
<table width=100% cellpadding="5" cellspacing="2" align="center">
<tr>
<td colspan="2" align="center"> <h2><strong>FORM-10</strong></h2></td>
</tr>
<tr>
<td align="right"> <strong>Serial_No:</strong></td>
<td><input type="text" name="sl_no" placeholder="Serial_no" required></td>
</tr>
<tr>
<td align="right"> <strong>Description :</strong></td>
<td><input type="text" name="description" placeholder="description" required></td>
</tr>
<tr>
<td align="right"> <strong>Location:</strong></td>
<td><input type="text" name="location" placeholder="location" required></td>
</tr>
<tr>
<td align="right"> <strong>Reference_no:</strong></td>
<td><input type="text" name="reference_no" placeholder="reference_no" required></td>
</tr>
<tr>
<td align="right"> <strong>Date_of_Acquisition:</strong></td>
<td><input type="text" name="date_of_acquisation" id = "datepicker" placeholder="date_of_acquisation" required></td>
</tr>
<tr>
<td align="right"> <strong>Total_no_of_Units:</strong></td>
<td><input type="text" name="total_no_of_units" id="total_no_of_units" onkeyup="calculate()" placeholder="total_no_of_units" required></td>
</tr>
<tr>
<td align="right"> <strong>Cost per Unit:</strong></td>
<td><input type="text" name="cost_per_unit" id="cost_per_unit" onkeyup="calculate()" placeholder="cost_per_unit" required></td>
</tr>
<tr>
<td align="right"> <strong>Total Acquisition Cost:</strong></td>
<td><input type="text" name="total_cost_of_acquistion" id="total_cost_of_acquistion" placeholder="total_cost_of_acquistion" required></td>
</tr>
<tr>
<td align="right"> <strong>Asset Life:</strong></td>
<td><input type="text" name="life_of_assets_per_codal" placeholder="life_of_assets_per_codal" required></td>
</tr>
<tr>
<td align="right"> <strong>Years asset used:</strong></td>
<td><input type="text" name="no_year_assets_use" placeholder="no_of_year_assets_use" required></td>
</tr>
<tr>
<td align="right"> <strong>Depriciation Rate:</strong></td>
<td><input type="text" name="rate_depreciation" placeholder="rate_depreciation" required></td>
</tr>
<tr>
<td align="right"> <strong>Accumulated Depriciation:</strong></td>
<td><input type="text" name="accumulate_depreciation" placeholder="accumulate_depreciation_till_31/03/2016" required></td>
</tr>
<tr>
<td align="right"> <strong>Valuation:</strong></td>
<td><input type="text" name="value_as_on" placeholder="value_as_on_31/03/2016" required></td>
</tr>
<tr>
<td align="right"> <strong>Remarks:</strong></td>
<td><input type="text" name="remarks" placeholder="remarks" ></td>
</tr>
<!-- <tr>
<td align="right"> <strong>Status: </strong></td>
<td><select name="status" required>
<option></option>
<option>New</option>
<option>Old</option>
<option>Lost</option>
<option>Damage</option>
<option>Subject for Replacement</option>
<option>Archive</option>
</select>
</td>
</tr>-->
<tr>
<td colspan="2" align="center"><input type='submit' value=' Save ' name='submit'>
</tr>
</table>
<h4 align="right"><a href="mainpage1.php">BACK</a></h4>
</div>
</form>
<script>
function calculate(){
var number = $('#total_no_of_units').val();
var unitCost = $('#cost_per_unit').val();
var totalCost = $('#total_cost_of_acquistion').val();
if(number=='' || unitCost==''){
$('#total_cost_of_acquistion').val('0');
return false;
}
else{
$('#total_cost_of_acquistion').val(number*unitCost);
}
}
</script>
</body>
</html>发布于 2017-06-17 00:08:32
如果你正在讨论当一个字段的值发生变化时实时更新另一个字段,那么你将不得不使用客户端脚本,如Javascript,Node,Jquery等。我建议为所有字段设置一个默认值,这样你就不必检查该值是否为空。
<input id='field1' type='text' value='0' />
<input id='field2' type='text' value='0' />
<input id='answer' type='text' value='0' />
<script>
$('#field1').on('input', function(e){
$('#answer').val(parseInt($(this).val()) * parseInt($('#field2').val()));
});
$('#field2').on('input', function(e){
$('#answer').val(parseInt($(this).val()) * parseInt($('#field1').val()));
});
</script>您可以根据需要细分出正确的字段并更改数学,但概念是相同的。
如果您只是在提交数据之后进行更改,那么它只是在适当的值域中将值从服务器端代码回显到客户端代码。
我希望这能回答你的问题。
发布于 2017-06-17 00:13:43
您可以使用jquery在用户事件上显示total_cost_acquisition。
像这样,
$( document ).ready(function() {
$('[name="cost_per_unit"]').keyup(function() {
calculateTotal();
});
$('[name="total_no_of_units"]').keyup(function() {
calculateTotal();
});
});
function calculateTotal(){
var total = ($('[name="cost_per_unit"]').val() * $('[name="total_no_of_units"]').val());
$('[name="total_cost_of_acquistion"]').val(total);
}希望它能解决你的问题
https://stackoverflow.com/questions/44593333
复制相似问题