คำนวณค่าตัวเลข ขณะพิม


<script type="text/javascript" src="gajax.js"></script>


<form id="form1" name="form1" method="post" action="test1.php">


<table width="630" border="0" cellspacing="0" cellpadding="3">


  <tr>


    <td width="558" align="center">


<table width="540" border="1" cellpadding="3" cellspacing="0" class="style1" id="tblInsertRowPHP">


<tr>


        <td>1. <input name="txtRow[]" type="text" size="45" id="txtRow1" /></td>


        <td><input name="td1" type="text" id="txtCol1"/></td>


      </tr>


  <tbody></tbody>


      <tr>


        <td align="center">รวมทั้งสิ้น</td>


        <td><input name="" type="text" id="sum" /> บาท</td>


      </tr>


</table></td>


    <td width="54"><input type="button" value="เพิ่ม" onClick="insertRowPHP();" /></td>


  </tr>


  <tr>


      <td class="style1">(ตัวอักษร <input name="" type="text" size="50" />  ) รวมเป็นเงิน(บาท)


 <input type="submit" value="submit" /></td>


  </tr>


</table>


</form>


 


 


 


 


<script type="text/javascript">


function insertRowPHP()


{


  var tbl = document.getElementById('tblInsertRowPHP');


  var iteration = tbl.tBodies[0].rows.length;


  newRow = tbl.tBodies[0].insertRow(-1);


 


  var newCell = newRow.insertCell(0);


  newCell.innerHTML = iteration + 1 + '. ';


  var el = document.createElement('input');


  el.type = 'text';


  el.name = 'txtRow[]';


  el.id = 'txtRow' + (iteration+1);


  el.value = 'txtRow' + (iteration+1);


  el.size = 45;


  newCell.appendChild(el);


 


 


  var newCell1 = newRow.insertCell(-1);


  var el2 = document.createElement('input');


  el2.type = 'text';


  el2.name = 'txtCol[]';


  el2.id = 'txtCol' + (iteration+1);


  el2.value = 'txtCol' + (iteration+1);


  newCell1.appendChild(el2);


}


</script>



ถ้ากดเพิ่มหลายๆตารางแล้ว จะใส่ค่าตัวเลขเข้าไปที่ ช่อง txtCol แล้วให้มันคำนวณเลย เอามาบวกกันต้องทำไงครับ

และก็จะเอาค่าของแต่ละช่องไปเก็บใขฐานข้อมูลด้วย

09 พ.ย. 2553 2 1,664

http://www.goragod.com/...80...B8%82 และตัวอย่างอื่นๆ อีกเพียบ บนเว็บที่จะช่วยตอบคำถามนี้ได้ เช่น ตัวเลข
#1

ถ้าต้องการให้ input ที่เเพิ่มใหม่ สามารถดัก event ได้



el.onkeypress = function (){

   // คำสั่งคำนวณเมื่อกดคีย์

};
#2
ความคิดเห็น
ไฟล์อัปโหลด ชนิด jpg, jpeg ขนาดไฟล์ไม่เกิน 1024
^