<!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" dir="ltr" lang="th" xml:lang="th"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>calculate number</title> <script type="text/javascript"> function textclear(){ var f = document.getElementById('box'); for(var i=0;i<f['hdnLine'].value;i++){ var chk = f['receive'+i]; var k = f['k'+i]; var p = f['p'+i]; var a = f['a'+i]; if(chk.checked==false){ k.value=""; p.value=""; a.value=""; k.readOnly = true; p.readOnly = true; f['k'+i].style.backgroundColor = "#e5e5e4"; f['p'+i].style.backgroundColor = "#e5e5e4"; }else{ k.readOnly = false; p.readOnly = false; f['k'+i].style.backgroundColor = "#fff"; f['p'+i].style.backgroundColor = "#fff"; } } var total = 0; for(var x=1;x<f['hdnLine'].value;x++){ var a = f['a'+x].value*1; total += a; } f['c'].value = total; } function textsum(){ var f = document.getElementById('box'); function calA(i){ var d = function (){ var k = f['k'+i]; var p = f['p'+i]; var a = f['a'+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'; } var total = 0; for(var x=1;x<f['hdnLine'].value;x++){ var a = f['a'+x].value*1; total += a; } f['c'].value = total; } return d; } for(var i=0;i<f['hdnLine'].value;i++){ f['k'+i].onkeyup = calA(i); f['p'+i].onkeyup = calA(i); } } </script> </head> <body> <form method="post" action="" name="box" id="box"> <input type="text" name="0" value="เลือก" size="1" disabled="disabled" /> <input type="text" name="a" value="จำนวน" disabled="disabled" /> <input type="text" name="p" value="ราคาต่อหน่วย" disabled="disabled" /> <input type="text" name="k" value="ราคารวม" disabled="disabled" /> <br /> <? $line=5; for($i=0;$i<=$line;$i++) { ?> <input type="checkbox" name="receive<?=$i;?>" id="receive<?=$i;?>" value="<?=$i;?>" onClick="textclear();" /> <input type="text" name="k<?=$i;?>" value="" onKeyUp="textsum();" onKeyDown="textsum();" readonly="true" style="background:#e5e5e4;" /> <input type="text" name="p<?=$i;?>" value="" onKeyUp="textsum();" onKeyDown="textsum();" readonly="true" style="background:#e5e5e4;"/> <input type="text" name="a<?=$i;?>" value="" readonly="true" /> <br/> <?php } ?> ยอดรวมทั้งหมด <input type="text" name="c" id="c" value="" readonly="true" /> บาท <br/> <input type="submit" name="submit" id="submit" value="submit" /> <input type="reset" name="reset" id="reset" value="reset" /> <input type="hidden" name="hdnLine" id="hdnLine" value="<?=$i;?>"> </form> <?php if(isset($_POST['submit'])){ for($i=0;$i<$_POST['hdnLine'];$i++){ if(trim($_POST['receive$i']) != ""){ echo "amount = ".$_POST['k$i']." "; echo "price = ".$_POST['p$i']." "; echo "sum = ".$_POST['a$i']." "; echo "<br />"; } } echo $_POST["receive$i"]; $total = $_POST['c']; echo "จำนวนรวมทั้งหมด".$total." บาท"; } ?> </body> </html>
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง