|
|
|
รบกวนดูโค้ดการคำนวณให้หน่อยค่ะ ต้องการหาค่าคูณแบบไม่ต้องกด submit ค่ะ |
|
|
|
|
|
|
|
เมื่อกรอกจำนวนที่สั่งจ่ายแล้วอยากให้ค่าที่คำนวณแสดงตรงราคารวมค่ะ ไม่รู้จะทำยังไงค่ะตัดแปลงโค้ด java script ไม่เปนค่ะ
รบกวนช่วยหน่อยนะค่ะ
Code (PHP)
<?
session_start();
if($_SESSION["Status"]== "")
echo "<SCRIPT LANGUAGE='JavaScript'>
alert('Plese Login!!')
window.location.href = '../Login/log-in.php';
</SCRIPT>";
elseif($_SESSION["Status"]== "USER")
echo "<SCRIPT LANGUAGE='JavaScript'>
alert('Plese Login!!')
window.location.href = '../Login/log-in.php';
</SCRIPT>";
?>
<?php
$_SESSION['pet_id']=$pet_id;
?>
<!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" />
<style type="text/css">
<!--
.style2 {color: #000000}
.style4 {color: #000000; font-size: 18px; }
.style1 {font-size: 18px}
-->
</style>
<script>
function textsum(){
function calA(i){
var d = function (){
var k = document.frm['aa[]'][i];
var p = document.frm['amount[]'][i];
var a = document.frm['cc[]'][i];
k.value = k.value.replace(/[^\d\.]/g,'');
p.value = p.value.replace(/[^\d\.]/g,'');
a.value = (k.value*1) * (p.value*1);
if (a.value <= 0){
a.style.color = 'red';
} else {
a.style.color = 'black';
}
}
return d;
}
for(var i=0;i<document.frm['aa[]'].length;i++){);
document.frm['aa[]'][i].onkeyup = calA(i);
document.frm['amount[]'][i].onkeyup = calA(i);
}
}
</script>
<script language="javascript">
function IsNumeric(sText,obj)
{
var ValidChars = "0123456789.";
var IsNumber=true;
var Char;
for (i = 0; i < sText.length && IsNumber == true; i++) {
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1) {
IsNumber = false;
}
}
if(IsNumber==false){
alert("พิมพ์ได้เฉพาะตัวเลขเท่านั้น");
obj.value=sText.substr(0,sText.length-1);
}
}
</script>
<script type="text/javascript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>
<body onLoad="MM_preloadImages('../img/m11.jpg','../img/m2.jpg','../img/m33.jpg','../img/m55.jpg','../img/m4.jpg')">
<table width="1020" border="0" align="center" bgcolor="#D4E0F0">
<tr>
<td height="195" colspan="6" background="../img/H1.jpg"> </td>
</tr>
<tr>
<td width="199"><div align="center"><a href="manage_pet_AM.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image2','','../img/m11.jpg',1)"><img src="../img/m1.jpg" name="Image2" width="150" height="50" border="0" id="Image2" /></a></div></td>
<td width="199"><div align="center"><a href="report_page.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image4','','../img/m33.jpg',1)"><img src="../img/m3.jpg" name="Image4" width="150" height="50" border="0" id="Image4" /></a></div></td>
<td width="199" bgcolor="#D4E0F0"><div align="center"><a href="set_page.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image7','','../img/m6.jpg',1)"><img src="../img/mm66.jpg" name="Image7" width="150" height="50" border="0" id="Image7" /></a></div></td>
<td width="199" bgcolor="#D4E0F0"><div align="center"><a href="contact.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image6','','../img/m55.jpg',1)"><img src="../img/m5.jpg" name="Image6" width="150" height="50" border="0" id="Image6" /></a></div></td>
<td width="207" bgcolor="#D4E0F0"><div align="center"><a href="logout.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image5','','../img/m4.jpg',1)"><img src="../img/m44.jpg" name="Image5" width="150" height="50" border="0" id="Image5" onclick="return confirm
('ออกจากระบบ!!')" /></a></div></td>
</tr> <tr bgcolor="#FFFFFF">
<td colspan="6" bgcolor="#FFFFFF"><center>
<div align="center">
<div align="right">
<table width="100%" border="0" align="center" bordercolor="#D4E0F0" bgcolor="#D4E0F0">
<tr>
<td colspan="4" bgcolor="#C0C0C0"><div align="center" > ข้อมูลสัตว์เลี้ยง </div></td>
</tr>
<tr>
<td width="27%"><div align="right">รหัสสัตว์เลี้ยง:</div></td>
<td width="19%"><label>
<input name="pet_id" type="hidden" value="<?php echo $pet_id ?>" />
<?php echo $pet_id ?> </label> </td>
<td width="21%"><div align="right">ประเภทสัตว์เลี้ยง:</div></td>
<td width="33%"><label>
<input name="pet_type" type="hidden" value="<?php echo $pet_type ?>" />
<?php echo $pet_type ?> </label> </td>
</tr>
<tr>
<td><div align="right">ชื่อสัตว์เลี้ยง:</div></td>
<td><label>
<input name="pet_name" type="hidden" value="<?php echo $pet_name ?>"/>
<?php echo $pet_name ?> </label></td>
<td><div align="right">ชื่อเจ้าของ:</div></td>
<td><label>
<input name="own_name" type="hidden" value="<?php echo $own_name ?>" />
<?php echo $own_name ?> </label> </td>
</tr>
<tr>
<td colspan="4"><div align="center">
<form action="chk_disshow.php" method="post" name="frm"><!--ส่งไปคำนวณเมื่อมีการ สั่งหนังสือเพิ่ม-->
<table width="90%" border="1" align="center" bordercolor="#fcf9cb" bgcolor="#fcf9cb">
<tr><th width="5%" align="center">ลบ</th>
<th width="10%" align="center">ลำดับ</th>
<th align="center">ชื่อยา</th>
<th width="10%" align="center">หน่วยนับ</th>
<th width="10%" align="center">ราคา/หน่วย</th>
<th width="20%" align="center">จำนวนคงเหลือ</th>
<th width="20%" align="center">จำนวนที่สั่งจ่าย</th>
<th width="15%" align="center">ราคารวม</th>
</tr>
<?php
$chk=$_POST['chk'];
$i=0;
$count=count($_SESSION['s_med_name']);
while($i<$count){
//$netprice=$_SESSION['s_med_price'][$i]*$_SESSION['s_med_amount'][$i];
echo "<tr>";
echo "<td align='center'><input type ='checkbox' name=del[] value='",$_SESSION['s_med_id'][$i],"'></td>";
echo "<td align='center'>",$i+1,"</td>";
echo "<td align='center'>".$_SESSION['s_med_name'][$i]."</td>";
echo "<td align='center'>".$_SESSION['s_med_unit'][$i]."</td>";
//echo "<td align='center'>".$_SESSION['s_med_price'][$i]."</td>";
echo "<td align='center'><input type='text' name='aa[]' value='".$_SESSION['s_med_price'][$i]."' onKeyUp='IsNumeric(this.value,this)' OnChange=\"textsum();\" onfocus=\"textsum();\" onblur=\"textsum();\" onkeyup=\"textsum();\" disable/></td>";
echo "<td align='center'>".$_SESSION['s_med_remain'][$i]."</td>";
echo "<td align='center'><input type='text' name='amount[]' value='",$_SESSION['s_med_amount'][$i],"' onKeyUp='IsNumeric(this.value,this)' OnChange=\"textsum();\" onfocus=\"textsum();\" onblur=\"textsum();\" onkeyup=\"textsum();\" /></td>";
echo "<td align='center'><input type='text' name='cc[]' /></td>";
//echo "<td align='center'>".$netprice."</td>";
echo "</tr>";
$i++;
$total+=$netprice;
}
?>
<? $a=$_SESSION['s_total']+$_SESSION['s_cost']; ?>
<tr>
<td colspan="7" align="right">ราคายาทั้งหมด</td>
<td align='center'><?php
echo $total;?></td>
<input name="total" type="hidden" value="<? echo $total; ?>" />
</tr>
<tr>
<td colspan="7" align="right">ค่ารักษาพยาบาล</td>
<td align="center"><label>
<input type="text" name="cost" value="<? echo $_SESSION['s_cost'] ; ?>" onKeyUp="IsNumeric(this.value,this)"/>
</label></td>
</tr>
<tr><input name="a" type="hidden" value="<? echo $a; ?>" />
<td colspan="7" align="right">รวมสุทธิ</td><td align="center"><? echo $a; ?></td></tr>
</table>
<br/>
<center>
<input type="submit" name="button" value="กลับไปหน้ารายการยา"/>
<input type="submit" name="button" value="คำนวณค่ายา">
<input type="submit" name="button" value="บันทึก">
<input type="submit" name="button" value="ลบยา" />
</center>
</form></div></td>
</tr>
</table>
</div>
</div>
</center></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="44" colspan="6" bgcolor="#D4E0F0"><table width="1016" height="42" border="0" align="center" bgcolor="#D4E0F0">
<tr bgcolor="#D4E0F0">
<td height="38" bgcolor="#C0C0C0"><div align="center">
<div align="center"></div>
<div align="center"></div>
<div align="center"></div>
<div align="center">
<div align="center"><span class="style4">คลินิก "หมา-แมว" อ.สันป่าตอง จ.เชียงใหม่ (ตรงข้ามกับ ธกส.สันป่าตอง) โทร.084-2229144</span> </div>
<div align="center" class="style2"></div>
<div align="center" class="style2"></div>
<div align="center" class="style2"></div>
<div align="center">
<div align="center" class="style2"></div>
<div align="center" class="style2"></div>
<div align="center">
<div align="center" class="style2"></div>
<div align="center" class="style2"></div>
<div align="center" class="style2"></div></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
Tag : PHP
|
|
|
|
|
|
Date :
2013-01-26 08:00:32 |
By :
samonggrue |
View :
1003 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ส่วนอันนี้เป็นโค้ดที่ทำก่อนหน้านี้ค่ะต้องคลิก คำนวณก่อนค่ะค่าถึงจะแสดง ต้องคลิกคำนวณสองรอบ ค่ารวมสุทธิถึงจะแสดง ต้องกดคลิกคลั้งเดียวแสดงเลยค่ะ หรือแสดงเอง Auto เลยก็ได้ แต่ไม่รู้จะทำไงดีค่ะ
Code (PHP)
<?
session_start();
if($_SESSION["Status"]== "")
echo "<SCRIPT LANGUAGE='JavaScript'>
alert('Plese Login!!')
window.location.href = '../Login/log-in.php';
</SCRIPT>";
elseif($_SESSION["Status"]== "USER")
echo "<SCRIPT LANGUAGE='JavaScript'>
alert('Plese Login!!')
window.location.href = '../Login/log-in.php';
</SCRIPT>";
?>
<?php
$_SESSION['pet_id']=$pet_id;
?>
<!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" />
<style type="text/css">
<!--
.style2 {color: #000000}
.style4 {color: #000000; font-size: 18px; }
.style1 {font-size: 18px}
-->
</style>
<script language="javascript">
function IsNumeric(sText,obj)
{
var ValidChars = "0123456789.";
var IsNumber=true;
var Char;
for (i = 0; i < sText.length && IsNumber == true; i++) {
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1) {
IsNumber = false;
}
}
if(IsNumber==false){
alert("พิมพ์ได้เฉพาะตัวเลขเท่านั้น");
obj.value=sText.substr(0,sText.length-1);
}
}
</script>
<script type="text/javascript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>
<body onLoad="MM_preloadImages('../img/m11.jpg','../img/m2.jpg','../img/m33.jpg','../img/m55.jpg','../img/m4.jpg')">
<table width="1020" border="0" align="center" bgcolor="#D4E0F0">
<tr>
<td height="195" colspan="6" background="../img/H1.jpg"> </td>
</tr>
<tr>
<td width="199"><div align="center"><a href="manage_pet_AM.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image2','','../img/m11.jpg',1)"><img src="../img/m1.jpg" name="Image2" width="150" height="50" border="0" id="Image2" /></a></div></td>
<td width="199"><div align="center"><a href="report_page.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image4','','../img/m33.jpg',1)"><img src="../img/m3.jpg" name="Image4" width="150" height="50" border="0" id="Image4" /></a></div></td>
<td width="199" bgcolor="#D4E0F0"><div align="center"><a href="set_page.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image7','','../img/m6.jpg',1)"><img src="../img/mm66.jpg" name="Image7" width="150" height="50" border="0" id="Image7" /></a></div></td>
<td width="199" bgcolor="#D4E0F0"><div align="center"><a href="contact.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image6','','../img/m55.jpg',1)"><img src="../img/m5.jpg" name="Image6" width="150" height="50" border="0" id="Image6" /></a></div></td>
<td width="207" bgcolor="#D4E0F0"><div align="center"><a href="logout.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image5','','../img/m4.jpg',1)"><img src="../img/m44.jpg" name="Image5" width="150" height="50" border="0" id="Image5" onclick="return confirm
('ออกจากระบบ!!')" /></a></div></td>
</tr> <tr bgcolor="#FFFFFF">
<td colspan="6" bgcolor="#FFFFFF"><center>
<div align="center">
<div align="right">
<table width="100%" border="0" align="center" bordercolor="#D4E0F0" bgcolor="#D4E0F0">
<tr>
<td colspan="4" bgcolor="#C0C0C0"><div align="center" > ข้อมูลสัตว์เลี้ยง </div></td>
</tr>
<tr>
<td width="27%"><div align="right">รหัสสัตว์เลี้ยง:</div></td>
<td width="19%"><label>
<input name="pet_id" type="hidden" value="<?php echo $pet_id ?>" />
<?php echo $pet_id ?> </label> </td>
<td width="21%"><div align="right">ประเภทสัตว์เลี้ยง:</div></td>
<td width="33%"><label>
<input name="pet_type" type="hidden" value="<?php echo $pet_type ?>" />
<?php echo $pet_type ?> </label> </td>
</tr>
<tr>
<td><div align="right">ชื่อสัตว์เลี้ยง:</div></td>
<td><label>
<input name="pet_name" type="hidden" value="<?php echo $pet_name ?>"/>
<?php echo $pet_name ?> </label></td>
<td><div align="right">ชื่อเจ้าของ:</div></td>
<td><label>
<input name="own_name" type="hidden" value="<?php echo $own_name ?>" />
<?php echo $own_name ?> </label> </td>
</tr>
<tr>
<td colspan="4"><div align="center">
<form action="chk_disshow.php" method="post"><!--ส่งไปคำนวณเมื่อมีการ สั่งหนังสือเพิ่ม-->
<table width="90%" border="1" align="center" bordercolor="#fcf9cb" bgcolor="#fcf9cb">
<tr><th width="5%" align="center">ลบ</th>
<th width="10%" align="center">ลำดับ</th>
<th align="center">ชื่อยา</th>
<th width="10%" align="center">หน่วยนับ</th>
<th width="10%" align="center">ราคา/หน่วย</th>
<th width="20%" align="center">จำนวนคงเหลือ</th>
<th width="20%" align="center">จำนวนที่สั่งจ่าย</th>
<th width="15%" align="center">ราคารวม</th>
</tr>
<?php
$chk=$_POST['chk'];
$i=0;
$count=count($_SESSION['s_med_name']);
while($i<$count){
$netprice=$_SESSION['s_med_price'][$i]*$_SESSION['s_med_amount'][$i];
echo "<tr>";
echo "<td align='center'><input type ='checkbox' name=del[] value='",$_SESSION['s_med_id'][$i],"'></td>";
echo "<td align='center'>",$i+1,"</td>";
echo "<td align='center'>".$_SESSION['s_med_name'][$i]."</td>";
echo "<td align='center'>".$_SESSION['s_med_unit'][$i]."</td>";
echo "<td align='center'>".$_SESSION['s_med_price'][$i]."</td>";
echo "<td align='center'>".$_SESSION['s_med_remain'][$i]."</td>";
echo "<td align='center'><input type='text' name=amount[] value='",$_SESSION['s_med_amount'][$i],"' onKeyUp='IsNumeric(this.value,this)'></td>";
echo "<td align='center'>".$netprice."</td>";
echo "</tr>";
$i++;
$total+=$netprice;
}
?>
<? $a=$_SESSION['s_total']+$_SESSION['s_cost']; ?>
<tr>
<td colspan="7" align="right">ราคายาทั้งหมด</td>
<td align='center'><?php
echo $total;?></td>
<input name="total" type="hidden" value="<? echo $total; ?>" />
</tr>
<tr>
<td colspan="7" align="right">ค่ารักษาพยาบาล</td>
<td align="center"><label>
<input type="text" name="cost" value="<? echo $_SESSION['s_cost'] ; ?>" onKeyUp="IsNumeric(this.value,this)"/>
</label></td>
</tr>
<tr><input name="a" type="hidden" value="<? echo $a; ?>" />
<td colspan="7" align="right">รวมสุทธิ</td><td align="center"><? echo $a; ?></td></tr>
</table>
<br/>
<center>
<input type="submit" name="button" value="กลับไปหน้ารายการยา"/>
<input type="submit" name="button" value="คำนวณค่ายา">
<input type="submit" name="button" value="บันทึก">
<input type="submit" name="button" value="ลบยา" />
</center>
</form></div></td>
</tr>
</table>
</div>
</div>
</center></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="44" colspan="6" bgcolor="#D4E0F0"><table width="1016" height="42" border="0" align="center" bgcolor="#D4E0F0">
<tr bgcolor="#D4E0F0">
<td height="38" bgcolor="#C0C0C0"><div align="center">
<div align="center"></div>
<div align="center"></div>
<div align="center"></div>
<div align="center">
<div align="center"><span class="style4">คลินิก "หมา-แมว" อ.สันป่าตอง จ.เชียงใหม่ (ตรงข้ามกับ ธกส.สันป่าตอง) โทร.084-2229144</span> </div>
<div align="center" class="style2"></div>
<div align="center" class="style2"></div>
<div align="center" class="style2"></div>
<div align="center">
<div align="center" class="style2"></div>
<div align="center" class="style2"></div>
<div align="center">
<div align="center" class="style2"></div>
<div align="center" class="style2"></div>
<div align="center" class="style2"></div></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
|
|
|
|
|
Date :
2013-01-26 08:07:27 |
By :
samonggrue |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
งมๆซามๆ ได้ละค่ะ
|
|
|
|
|
Date :
2013-01-26 12:52:25 |
By :
samonggrue |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|