Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > PHP > PHP Forum > javascript วนลูปอ่านค่าแล้วนำมาบวกกัน แต่เหมือนมันเจอ input text ตัวเดียว ทั้งที่มีอยู่หลายตัว


[PHP] javascript วนลูปอ่านค่าแล้วนำมาบวกกัน แต่เหมือนมันเจอ input text ตัวเดียว ทั้งที่มีอยู่หลายตัว

 
Topic : 050794



โพสกระทู้ ( 6 )
บทความ ( 0 )



สถานะออฟไลน์



โค้ด javascript ที่สร้าง input text ตามจำนวนที่กรอก

Code (JavaScript)
01.function CreateNewRow()
02.    {
03.        var intLine = parseInt(document.getElementById('hdnMaxLine').value);
04.        intLine++;
05.             
06.        var theTable = document.all.tbExp
07.        var newRow = theTable.insertRow(theTable.rows.length)
08.        newRow.id = newRow.uniqueID
09. 
10.        var newCell
11.         
12.        //*** Column 1 ***//
13.        newCell = newRow.insertCell(0);
14.        newCell.id = newCell.uniqueID;
15.        newCell.setAttribute("className", "css-name");
16.        newCell.innerHTML = "<center><SELECT NAME=\"Column1_"+intLine+"\" ID=\"Column1_"+intLine+"\"></SELECT></center>";
17. 
18.        //*** Column 2 ***//
19.        newCell = newRow.insertCell(1);
20.        newCell.id = newCell.uniqueID;
21.        newCell.setAttribute("className", "fieldcell");
22.        newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"Column2_"+intLine+"\" ID=\"Column2_"+intLine+"\"  VALUE=\"\"></center>";
23.         
24.        //*** Column 3 ***//
25.        newCell = newRow.insertCell(2);
26.        newCell.id = newCell.uniqueID;
27.        newCell.setAttribute("className", "moneycell");
28.        newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"Column3_"+intLine+"\" ID=\"Column3_"+intLine+"\" OnKeyUp=\"fnccal1();\" VALUE=\"\"></center>";
29.         
30.        //*** Column 4 ***//
31.        newCell = newRow.insertCell(3);
32.        newCell.id = newCell.uniqueID;
33.        newCell.setAttribute("className", "moneycell");
34.        newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"Column4_"+intLine+"\" ID=\"Column4_"+intLine+"\" OnKeyUp=\"fnccal2();\" VALUE=\"\"></center>";
35.         
36.         
37.         document.getElementById('hdnMaxLine').value =  intLine
38.    }
39.     
40.    function RemoveRow()
41.    {
42.        var intLine = parseInt(document.getElementById('hdnMaxLine').value);
43.        if(parseInt(intLine) > 0)
44.        {
45.                theTable = (document.all) ? document.all.tbExp :
46.                document.getElementById("tbExp")
47.                theTableBody = theTable.tBodies[0];
48.                theTableBody.deleteRow(intLine);
49.                intLine--;
50.         document.getElementById('hdnMaxLine').value =  intLine
51.        }  
52.    }  
53. 
54.    function GenerateRow()
55.    {
56.        var intRows = parseInt(document.getElementById('txtCount').value);
57.        for(i=0;i<intRows;i++)
58.        {
59.            CreateNewRow();
60.        }
61.    }


โค้ดผมเอาจากกระทู้นี้คับ https://www.thaicreate.com/php/forum/044751.html

ส่วนโค้ดที่วนลูปอ่านค่า ตามนี้ครับ

Code (JavaScript)
01.function fnccal1()
02.{
03.    var numrows = parseInt(document.getElementById('hdnMaxLine').value);
04.    for(intLine=1;intLine<numrows;intLine++)
05.    {
06.        var total = 0;
07.        if(document.getElementById && (element = document.getElementById('Column3_'+intLine)))
08.        {
09.            var sum = parseInt(document.getElementById('Column3_'+intLine).value);
10.            if(isNaN(sum))
11.            {
12.                sum = 0;
13.            }
14.            total += sum;
15.        }
16.        document.getElementById('Sumdebit').value = total;
17.    }
18.}


ผลลัพธ์คือ
ผลลัพธ์มันรวมแค่ช่องเดียว อยากให้มันรวมทั้งหมด

ทำยังไงจะให้ได้ผลที่ถูกต้อง ครับ



Tag : PHP

Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-10-27 09:47:23 By : jomyood007 View : 3130 Reply : 3
 

 

No. 1



โพสกระทู้ ( 74,059 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Quote:
var numrows = parseInt(document.getElementById('hdnMaxLine').value);



Code (JavaScript)
1.var numrows = parseInt(document.getElementById('hdnMaxLine').value);
2.alert(numrows);


มันมีค่าตามจำนวนที่สร้างหรือเปล่าครับ หรือไม่ลอง debug ค่าใน Loop เลยครับ

ใช้การ Debug เยอะ ๆ ครับ ชีวิตจะได้ง่ายขึ้นเยอะเลยยยยย
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-10-27 13:12:23 By : webmaster
 

 

No. 2



โพสกระทู้ ( 6 )
บทความ ( 0 )



สถานะออฟไลน์


ลองทำตามคำแนะนำ ตอนนี้แก้ได้แล้วครับ
ขอบคุณ mr.win มากครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-10-27 14:39:44 By : jomyood007
 

 

No. 3

Guest


ขอบคุณครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2019-01-23 14:52:27 By : eeie
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : javascript วนลูปอ่านค่าแล้วนำมาบวกกัน แต่เหมือนมันเจอ input text ตัวเดียว ทั้งที่มีอยู่หลายตัว
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่