|
|
|
จวนจะได้แล้ว type="text" onkeyup="calcBill()" มันหมายความว่ายังไง ช่วยทำให้หน่อยนะค่ะ |
|
|
|
|
|
|
|
คือมีคน ให้ code มา แล้วบอกให้เปลี่ยนตรง input
type="text" onkeyup="calcBill()" มันหมายความว่ายังไง ช่วยทำให้หน่อยนะค่ะ
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">
<script language='javascript' type='text/javascript'>
function addCommas(nStr) {
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
//*define object "Bill"
function Bill(){
//get form value
var unit = {
'water' : document.form2.wvalue.value,
'fire' : document.form2.fvalue.value,
'phone' : document.form2.pvalue.value
}
var rate = {
'water' : document.form2.u_water.value,
'fire' : document.form2.u_fire.value,
'phone' : document.form2.u_phone.value
}
//private function
this.calc = function(unit, rate){
unit = parseFloat(unit);
rate = parseFloat(rate);
if(!unit || !rate){return 0;}
return unit * rate;
}
//public properties
this.water = this.calc(unit['water'],rate['water']);
this.fire = this.calc(unit['fire'],rate['fire']);
this.phone = this.calc(unit['phone'],rate['phone']);
}
function calcBill(){
var bill = new Bill();
document.form2.total_water.value = addCommas(bill.water.toFixed(2));
document.form2.total_fire.value = addCommas(bill.fire.toFixed(2));
document.form2.total_phone.value = addCommas(bill.phone.toFixed(2));
document.form2.be_total.value = addCommas((bill.water + bill.fire + bill.phone).toFixed(2));
}
</script>
<head>
<style type="text/css">
<!--
.style14 {color: #FFFFFF}
.style15 { color: #FFFFFF;
font-weight: bold;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<link href="css/new.css" rel="stylesheet" type="text/css">
<title>ระบบบริหารงานห้องเช่า</title>
<script language='javascript' type='text/javascript'>
function water(){
var water = document.form2.wvalue.value;
var se2 = document.form2.u_water.value;
if(water == "" || water == ""){return false;}
var total = 0;
total = Number(water) * Number(se2);
form2.total_water.value = addCommas(total.toFixed(2));
}
function addCommas(nStr) {
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
</script>
<script language='javascript' type='text/javascript'>
function fire(){
var fire = document.form2.fvalue.value;
var se1 = document.form2.u_fire .value;
if(fire == "" || fire == ""){return false;}
var total = 0;
total = Number(fire) * Number(se1);
form2.total_fire.value = addCommas(total.toFixed(2));
}
</script>
<script language='javascript' type='text/javascript'>
function phone1(){
var p1 = document.form2.pvalue.value;
var up = document.form2.u_phone .value;
if(p1 == "" || p1 == ""){return false;}
var total = 0;
total = Number(p1) * Number(up);
form2.total_phone.value = addCommas(total.toFixed(2));
}
</script>
<script language='javascript' type='text/javascript'>
function total(){
var phone = document.form2.total_phone.value;
var fire = document.form2.total_fire .value;
var wate = document.form2.total_water .value;
if(phone == "" || phone == ""){return false;}
var total = 0;
total = Number(phone) + Number(fire)+ Number(wate);
form2.be_total.value = addCommas(total.toFixed(2));
}
</script>
<style type="text/css">
<!--
.style6 {font-weight: bold; font-style: italic; font-size: 16px;}
.style6 {color: #000080}
.style13 {color: #517dbf;
font-weight: bold;
}
.style8 {color: #FFFFFF;
font-size: 16px;
font-family: Verdana, Arial, Helvetica, sans-serif;
}
a:link {
color: #517DBF;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #517DBF;
}
a:hover {
text-decoration: none;
color: #FFFFFF;
}
a:active {
text-decoration: none;
color: #517DBF;
}
-->
</style>
</head>
<body>
<table width="90%" border="0" cellpadding="1" bgcolor="#66CCCC" align="center">
<tr valign="top">
<td width="82%" bgcolor="#EBF0F9"><form id="form2" name="form2" method="post" action="unitinsert.php">
<p> </p>
<table width="93%" border="0" align="center" cellpadding="1" bordercolor="#1E3C7B" bgcolor="#1E3C7B">
<tr>
<td bgcolor="#EBF0F9"><table width="100%" height="125" align="center">
<tr>
<td bgcolor="#1e3c7b"><span class="style14">ค่าโทรศัพท์ </span></td>
<td bgcolor="#1e3c7b"><span class="style15"></span></td>
<td bgcolor="#1e3c7b"><span class="style15"><strong>ค่าน้ำ</strong></span></td>
<td bgcolor="#1e3c7b"><span class="style15"></span></td>
<td bgcolor="#1e3c7b"><span class="style15"><strong>ค่าไฟ</strong></span></td>
<td bgcolor="#1e3c7b"><span class="style15"></span></td>
</tr>
<tr>
<td width="17%" bgcolor="#EBF0F9"><div align="right"><strong>ค่าโทรศัพท์</strong>:</div></td>
<td width="11%" bgcolor="#EBF0F9"><div align="left">
<input type='pvalue' id='pvalue' name='pvalue' value='' onkeyup='phone1()' size="10" />
</div></td>
<td width="22%" bgcolor="#EBF0F9"><div align="right"><strong>ค่าน้ำ : </strong></div></td>
<td width="14%" bgcolor="#EBF0F9"><div align="left">
<input name="wvalue" type="text" id="wvalue"onkeyup='water()' size="10" />
</div></td>
<td width="14%" bgcolor="#EBF0F9"><div align="right"><strong>ค่าไฟ:</strong></div></td>
<td width="22%" bgcolor="#EBF0F9"><div align="left">
<input type='fvalue' id='fvalue' name='fvalue' value='' onkeyup='fire()' size="10" />
</div></td>
</tr>
<tr>
<td bgcolor="#EBF0F9"><div align="right"><strong>ค่าโทร/ครั้ง : </strong></div></td>
<td bgcolor="#EBF0F9"><div align="left">
<input type='u_phone' id='u_phone' name='u_phone' value='' onkeyup='phone1()' size="10" />
</div></td>
<td bgcolor="#EBF0F9"><div align="right"><strong>ค่าน้ำ/หน่วย </strong>:</div></td>
<td bgcolor="#EBF0F9"><div align="left">
<input type='unit_water' id='u_water' name='u_water' value='' onkeyup='water()' size="10" />
</div></td>
<td bgcolor="#EBF0F9"><div align="right"><strong>ค่าไฟ</strong><strong>/หน่วย :</strong></div></td>
<td bgcolor="#EBF0F9"><input type='u_fire' id='u_fire' name='u_fire' value='' onkeyup='fire()' size="10" /></td>
</tr>
<tr>
<td bgcolor="#EBF0F9"><div align="right"><strong>รวม </strong><strong>:</strong></div></td>
<td bgcolor="#EBF0F9"><div align="left">
<input type='total_phone' id='total_phone' name='total_phone' value="0" onkeyup ='total()' size="10"/>
</div></td>
<td bgcolor="#EBF0F9"><div align="right"><strong>รวม : </strong></div></td>
<td bgcolor="#EBF0F9"><input type='total_water' id='total_water' name='total_water' value="0" onkeyup ='total()' size="10"/></td>
<td bgcolor="#EBF0F9"><div align="right"><strong>รวม:</strong></div></td>
<td bgcolor="#EBF0F9"><div align="left">
<input type='total_fire' id='total_fire' name='total_fire' value="0" onkeyup ='total()' size="10"/>
</div></td>
</tr>
<tr>
<td bgcolor="#EBF0F9"> </td>
<td bgcolor="#EBF0F9"> </td>
<td bgcolor="#EBF0F9"> </td>
<td bgcolor="#EBF0F9"> </td>
<td bgcolor="#EBF0F9"> </td>
<td bgcolor="#EBF0F9"> </td>
</tr>
<tr>
<td colspan="6" bgcolor="#1E3C7B"><div align="center">
<span class="style14">รวม : </span>
<input type='be_total' id='be_total' name='be_total' size="10"/>
<span class="style14">
บาท</span></div></td>
</tr>
</table></td>
</tr>
</table>
<p align="center"> </p>
<p align="center"> </p>
<p> </p>
</form>
</td>
</tr>
</table>
</body>
</html>
Tag : - - - -
|
|
|
|
|
|
Date :
2009-10-23 08:02:31 |
By :
aung |
View :
926 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ONKeyUp เมื่อมีการกดปุ่มแล้วปล่อยปุ่มขึ้นน่ะครับ
|
|
|
|
|
Date :
2009-10-23 08:39:48 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|