|
 |
|
จะคำนวนค่าใช้จ่าย รวมค่าอัตโนมัติเมื่อกรอกข้อมูล ได้อย่างไรครับ |
|
 |
|
|
 |
 |
|
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>การคำนวณตัวเลขอัตโนมัติขณะกรอก</title>
<script type="text/javascript" src="http://www.goragod.com/js/gajax.js"></script>
<style type="text/css">
html,body{height:100%;margin:0;padding:0}
body{font-size:9pt;color:#5C5C5C;font-family:Tahoma}
div.warper{display:block;text-align:center;min-height:100%;height:auto !important;height:100%;margin:10px auto -90px}
div.content{margin:10px}
div.ads{text-align:center;display:block}
</style>
</head>
<body>
<div class="content">
จำนวนที่ใช้-------------------------------ราคาต่อหน่วย------------------------------รวม
<form method="get" action="calc.php">
<?
include "connectdb.php";
$strSQL2 = "SELECT * FROM general_rate ";
$objQuery2 = mysql_query($strSQL2) or die ("Error Query [".$strSQL2."]");
$i =0;
while($objResult2 = mysql_fetch_array($objQuery2))
{
$i = $i + 1;
?>
<p><input type="text" id="amount1" value="0" /> * <input type="text" id="price1" readonly ="true" value="<?php echo $objResult2["Unit_Price"];?>" > = <input type="text" id="sum1" name="sum[]" readonly="true" /></p>
<?
}
?>
รวมทั้งสิ้น:<input type="text" id="allsum" name="sum[]" readonly="true" />
<script type="text/javascript">
<!--
/* ตัวเลขเท่านั้น */
var numberOnly = function(event) {
var key = event.which || event.keyCode;
if(!((key > 47 && key < 58) || key == 8 || key == 9 || key == 37 || key == 39)) {
GEvent.stop(event);
return false;
}else {
return true;
}
};
/* ตัวเลขและจุดเท่านั้น */
var currencyOnly = function(event) {
var key = event.which || event.keyCode;
if(!((key > 47 && key < 58) || key == 8 || key == 9 || key == 37 || key == 39 || key == 46)) {
GEvent.stop(event);
return false;
}else {
return true;
}
};
/* หาผลคูณ */
var calc = function(event) {
var amount = parseFloat($E('amount1').value);
amount = isNaN(amount) ? 0 : amount;
var price = parseFloat($E('price1').value);
price = isNaN(price) ? 0 : price;
$E('sum1').value = amount * price;
};
/* อีเว้นต์สำหรับกรอกกตัวเลขเท่านั้น */
$G('amount1').addEvent('keypress', numberOnly);
$G('price1').addEvent('keypress', currencyOnly);
/* อีเวนต์สำหรับการคำนวณ */
$G('amount1').addEvent('keyup', calc);
$G('price1').addEvent('keyup', calc);
$G('amount1').addEvent('change', calc);
$G('price1').addEvent('change', calc);
/* เรียกคำนวณครั้งแรกตอนเริ่มต้น */
calc.call(this);
//-->
</script>
<!-- Code -->
</div>
</body>
</html>
กำลังทำโปรเจคจัดการหอพัก มีคำนวนค่าใช้จ่ายรายเดือน หากมีการดึงข้อมูลจากฐานข้อมูลมาคำนวนขึ้นอยู่กับจำนวนแถวของฐานข้อมูล จะคำนวนค่าอัติโนมัติในทุกๆแถว ทำอย่างไรครับ
และเรื่องแสดงหมวดหมู่จาก combobox ที่primay key เป็น ค่า char ก็ยังทำไม่ได้ ผมมือใหม่ครับT^T
https://www.thaicreate.com/php/forum/092254.html
Tag : PHP, MySQL, Action Script, Ajax

|
|
 |
 |
 |
 |
Date :
2013-03-14 09:29:22 |
By :
mut2551 |
View :
2857 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เปลี่ยนวิธีการถามใหม่ครับ 
|
 |
 |
 |
 |
Date :
2013-03-14 21:31:25 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|