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 > Client Script Forum > จะเพิ่ม record เมื่อกด ปุ่ม แต่เวลาเพิ่ม ให้เพิ่มตามกลุ่มที่เพิ่มอะคะ ทำยังไงคะ


[PHP] จะเพิ่ม record เมื่อกด ปุ่ม แต่เวลาเพิ่ม ให้เพิ่มตามกลุ่มที่เพิ่มอะคะ ทำยังไงคะ

 
Topic : 060519



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



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



ask3

คือ เวลาเรากด Add Board ก็หมายถึงการเพิ่มบอร์ด แล้วในบอร์ดนี้ จะให้มีรายการอะไรบ้าง ก็ให้กด Add Item

ในภาพนี้ บอร์ดมี 2 บอร์ดนะคะ

แล้วเวลาเรากด Add Item บอร์ดที่ 1 แทนที่มันจะไปเพิ่ม record ในบอร์ดที่ 1 มันดันไปเพิ่ม ในส่วนของ record ที่ 2 นะคะ

ถ้าเรากด Add Item อันไหนก็ตามแต่ มันจะไปเพิ่ม record ในบอร์ดล่าสุดที่เราเพิ่มนะคะ

เรา จะต้องเอาไปผูกกับ Table หรือเปล่าคะ ??



Code นะคะ

Code (JavaScript)
001.function getCustomBoardRows(i, type){
002.    //alert(type); ประเภทปุ่ม button มีสองประเภทคือ btn_board, btn_boardStandard
003.    return '<u><b>บอร์ดที่ '+i+'</b></u> จำนวนบอร์ด <INPUT TYPE="TEXT" SIZE="3" NAME="txtBoardSize_'+i+'" ID="txtBoardSize_'+i+'" class="inputtext_nfixw" VALUE=""> ชนิดของบอร์ด <INPUT TYPE="TEXT" SIZE="15" NAME="txtBoardType_'+i+'" ID="txtBoardType_'+i+'" class="inputtext_nfixw" VALUE=""> หมายเหตุ <INPUT TYPE="TEXT" SIZE="45" NAME="txtBoardType_'+i+'" ID="txtBoardType_'+i+'" class="inputtext_nfixw" VALUE=""> <input name="btnAdd[]" type="button" id="btnAdd_ItemBoardStandard" class="button" value="+Add item" onClick="CreateNewItem(\''+type+'\',\''+i+'\')">';
004.}
005. 
006.function getStandBoardRows(i, type){
007.    //alert(type); ประเภทปุ่ม button มีสองประเภทคือ btn_board, btn_boardStandard
008.    return '<u><b>บอร์ดที่ '+i+'</b></u> จำนวนบอร์ด <INPUT TYPE="TEXT" SIZE="3" NAME="txtBoardSize_'+i+'" ID="txtBoardSize_'+i+'" class="inputtext_nfixw" VALUE=""> ชนิดของบอร์ด <INPUT TYPE="TEXT" SIZE="15" NAME="txtBoardType_'+i+'" ID="txtBoardType_'+i+'" class="inputtext_nfixw" VALUE=""> หมายเหตุ <INPUT TYPE="TEXT" SIZE="45" NAME="txtBoardType_'+i+'" ID="txtBoardType_'+i+'" class="inputtext_nfixw" VALUE=""> <input name="btnAdd[]" type="button" id="btnAdd_ItemBoardStandard" class="button" value="+Add item" onClick="CreateNewItem(\''+type+'\',\''+i+'\')">';
009.}
010. 
011.function getHeadColumn(type){
012.    var customHead = new Array("ชื่อกระเบื้อง","ขนาด","จำนวน","หน่วย","ประเภทแผ่น","ขนาดแผ่นตัด","ราคา/หน่วย","ราคารวม","หมายเหตุ","");
013.    var standHead  = new Array("หมายเลขบอร์ด","ชื่อบอร์ด","ประเภทบอร์ด","จำนวนบอร์ด","จำนวนบอร์ด","หมายเหตุ","");
014.    return (type == "btn_board")? customHead : standHead;
015.}
016. 
017.function CreateNewBoard(typeBoard){
018.    var typeBoard   = typeBoard.id
019.    var field       = getHeadColumn(typeBoard);
020.    var allColumn   = (typeBoard=="btn_board")? 10:7;
021.    intBoard = parseInt(document.frm_request.hdnMaxBoard.value);
022.    intBoard++;
023.    alert(intBoard);
024.    //eval("document.getElementById('tblBoard_"+intBoard+"')");
025.########################## บรรทัดนี้เราต้อง Fix ค่าตาราง หมายเลขตารางป่าวคะ ###############################
026.########################## แต่เราไม่รู้ว่า ตรงฟอร์ม HTML เราจะให้เลขไปต่อท้ายหลังยังไงนะคะเช่น tblBoard_1 tblBoard_2 อย่างนี้นะคะ ######
027.    var tableBoard = (typeBoard=="btn_board")? document.getElementById("tblBoard") : document.getElementById("tbl_boardstandard");
028. 
029.     
030.    for(intRow=0;intRow<2;intRow++){
031.        if(intRow==0){
032.            var insertRow1      = tableBoard.insertRow(0);
033.            var Row1Cell1       = insertRow1.insertCell(0); //
034.            Row1Cell1.colSpan = allColumn;
035.            Row1Cell1.style.backgroundColor = "#A7C520";
036.            Row1Cell1.style.color = "black";
037.            Row1Cell1.innerHTML = (typeBoard=="btn_board")? getCustomBoardRows(intBoard, typeBoard) : getStandBoardRows(intBoard, typeBoard);
038.        }else{
039.            var insertRow2      = tableBoard.insertRow(intRow);
040.            for(intCol=0;intCol<allColumn;intCol++){
041.                var Row2Cell        = insertRow2.insertCell(intCol);
042.                Row2Cell.style.backgroundColor = "#F5F6D4";
043.                Row2Cell.innerHTML="<center>"+field[intCol]+"</center>";
044.            }
045.        }
046.    }
047.    CreateNewItem(typeBoard);// typeBoard --> btn_board, btn_boardStandard
048.    document.frm_request.hdnMaxBoard.value = intBoard; /*set ค่า  hdnMaxBoard*/
049.}
050. 
051.function CreateNewItem(type,board){
052.    alert(board);
053.    var intLine = parseInt(document.frm_request.hdnMaxLine1.value);
054.    intLine++;
055.    var theTableBoard = (type=="btn_board")? document.getElementById("tblBoard") : document.getElementById("tbl_boardstandard");
056.    var insertRow       = theTableBoard.insertRow(2);
057.    var intField = (type=="btn_board")? 10:7;
058.    for(var ii=0;ii<intField;ii++){
059.        eval("var RowCell"+(ii+1)+" = insertRow.insertCell("+ii+");");
060.    }
061.    if(type=="btn_board"){
062.         
063.        RowCell1.innerHTML = "<center>"+intLine+" <SELECT NAME=\"txtProductName_"+intLine+"\" ID=\"txtProductName_"+intLine+"\"  class=\"inputtext_nfixw\" OnChange=\"JavaScript:doCallAjax('txtProductName_"+intLine+"','txtProductID_"+intLine+"','txtBaseUnit_"+intLine+"','txtPricePerUnit_"+intLine+"');\"></SELECT></center>"; //ตรงนี้อะ มีใช้หลายที่สามารถยุบเป็นฟังก์ชั่นแบบพี่ยุบได้นะ O kie
064.        //*** Create Option ***//
065.        CreateSelectOption("txtProductName_"+intLine,"productTiles"+intLine,intLine)
066.         
067.        RowCell2.innerHTML = "<center>"+intLine+" <INPUT TYPE=\"TEXT\" SIZE=\"20\" NAME=\"txtProductID_"+intLine+"\" ID=\"txtProductID_"+intLine+"\" class=\"inputtext_nfixw\" VALUE=\"\"><INPUT TYPE=\"TEXT\" SIZE=\"4\" NAME=\"txtBaseUnit_"+intLine+"\" ID=\"txtBaseUnit_"+intLine+"\" class=\"inputtext_nfixw\" VALUE=\"\"><INPUT TYPE=\"TEXT\" SIZE=\"4\" NAME=\"txtPricePerUnit_"+intLine+"\" ID=\"txtPricePerUnit_"+intLine+"\" class=\"inputtext_nfixw\" VALUE=\"\"></center>";
068.         
069.        RowCell3.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"1\" NAME=\"sizewidth_"+intLine+"\" ID=\"sizewidth_"+intLine+"\" class=\"inputtext_nfixw\" VALUE=\"\"> X <INPUT TYPE=\"TEXT\" SIZE=\"1\" NAME=\"sizelength_"+intLine+"\" ID=\"sizelength_"+intLine+"\"   class=\"inputtext_nfixw\" VALUE=\"\"></center>";
070.         
071.        RowCell4.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"2\" NAME=\"quantity_"+intLine+"\"  ID=\"quantity_"+intLine+"\"  class=\"inputtext_nfixw\" VALUE=\"\"></center>";
072.         
073.        RowCell5.innerHTML = "<center><SELECT NAME=\"unit_"+intLine+"\" ID=\"unit_"+intLine+"\" class=\"inputtext_nfixw\"  OnChange=\"JavaScript: doCalPrice('txtProductID_"+intLine+"','quantity_"+intLine+"','unit_"+intLine+"','pricetotal_"+intLine+"');\"></SELECT></center>";
074.        //*** Create Option ***//
075.        CreateSelectOption("unit_"+intLine,"unit_"+intLine,intLine)
076.         
077.        RowCell5.innerHTML = "<center><SELECT NAME=\"typepcs_"+intLine+"\" ID=\"typepcs_"+intLine+"\" class=\"inputtext_nfixw\" ></SELECT></center>";
078.        //*** Create Option ***//
079.        CreateSelectOption("typepcs_"+intLine,"typepcs_"+intLine,intLine)
080.         
081.        RowCell6.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"1\" NAME=\"sizewidth_subpcs_"+intLine+"\" ID=\"sizewidth_subpcs_"+intLine+"\"   class=\"inputtext_nfixw\" VALUE=\"\"> X <INPUT TYPE=\"TEXT\" SIZE=\"1\" NAME=\"sizelength_subpcs_"+intLine+"\" ID=\"sizelength_subpcs_"+intLine+"\" class=\"inputtext_nfixw\" VALUE=\"\"></center>";
082.         
083.        RowCell7.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"priceperunit_"+intLine+"\" ID=\"priceperunit_"+intLine+"\"   class=\"inputtext_nfixw\" VALUE=\"\"></center>";
084.         
085.        RowCell8.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"pricetotal_"+intLine+"\" ID=\"pricetotal_"+intLine+"\"   class=\"inputtext_nfixw\" VALUE=\"\"></center>";
086.         
087.        RowCell9.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"15\" NAME=\"remark_"+intLine+"\" ID=\"remark_"+intLine+"\"   class=\"inputtext_nfixw\" VALUE=\"\"></center>";
088.         
089.        RowCell10.innerHTML = "<center><input name=\"btnDel\" type=\"button\" id=\"btnDel\" value=\"-\" onClick=\"RemoveRow('row_"+intLine+"');\"></center>";
090.         
091.    }else{
092. 
093.        RowCell1.innerHTML = "<center>"+intLine+" <SELECT NAME=\"txtProductName_"+intLine+"\" ID=\"txtProductName_"+intLine+"\"  class=\"inputtext_nfixw\" OnChange=\"JavaScript:doCallAjax('txtProductName_"+intLine+"','txtProductID_"+intLine+"','txtBaseUnit_"+intLine+"','txtPricePerUnit_"+intLine+"');\"></SELECT></center>";
094.        //*** Create Option ***//
095.        CreateSelectOption("txtProductName_"+intLine,"productTiles"+intLine,intLine)
096.         
097.        RowCell2.innerHTML = "<center>"+intLine+" <INPUT TYPE=\"TEXT\" SIZE=\"20\" NAME=\"txtProductID_"+intLine+"\" ID=\"txtProductID_"+intLine+"\" class=\"inputtext_nfixw\" VALUE=\"\"><INPUT TYPE=\"TEXT\" SIZE=\"4\" NAME=\"txtBaseUnit_"+intLine+"\" ID=\"txtBaseUnit_"+intLine+"\" class=\"inputtext_nfixw\" VALUE=\"\"><INPUT TYPE=\"TEXT\" SIZE=\"4\" NAME=\"txtPricePerUnit_"+intLine+"\" ID=\"txtPricePerUnit_"+intLine+"\" class=\"inputtext_nfixw\" VALUE=\"\"></center>";
098.         
099.        RowCell3.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"1\" NAME=\"sizewidth_"+intLine+"\" ID=\"sizewidth_"+intLine+"\" class=\"inputtext_nfixw\" VALUE=\"\"> X <INPUT TYPE=\"TEXT\" SIZE=\"1\" NAME=\"sizelength_"+intLine+"\" ID=\"sizelength_"+intLine+"\"   class=\"inputtext_nfixw\" VALUE=\"\"></center>";
100.         
101.        RowCell4.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"2\" NAME=\"quantity_"+intLine+"\"  ID=\"quantity_"+intLine+"\"  class=\"inputtext_nfixw\" VALUE=\"\"></center>";
102.         
103.        RowCell5.innerHTML = "<center><SELECT NAME=\"unit_"+intLine+"\" ID=\"unit_"+intLine+"\" class=\"inputtext_nfixw\"  OnChange=\"JavaScript: doCalPrice('txtProductID_"+intLine+"','quantity_"+intLine+"','unit_"+intLine+"','pricetotal_"+intLine+"');\"></SELECT></center>";
104.        //*** Create Option ***//
105.        CreateSelectOption("unit_"+intLine,"unit_"+intLine,intLine)
106.         
107.        RowCell5.innerHTML = "<center><SELECT NAME=\"typepcs_"+intLine+"\" ID=\"typepcs_"+intLine+"\" class=\"inputtext_nfixw\" ></SELECT></center>";
108.        //*** Create Option ***//
109.        CreateSelectOption("typepcs_"+intLine,"typepcs_"+intLine,intLine)
110.         
111.        RowCell6.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"1\" NAME=\"sizewidth_subpcs_"+intLine+"\" ID=\"sizewidth_subpcs_"+intLine+"\"   class=\"inputtext_nfixw\" VALUE=\"\"> X <INPUT TYPE=\"TEXT\" SIZE=\"1\" NAME=\"sizelength_subpcs_"+intLine+"\" ID=\"sizelength_subpcs_"+intLine+"\" class=\"inputtext_nfixw\" VALUE=\"\"></center>";
112.         
113.        RowCell7.innerHTML = "<center><input name=\"btnDel\" type=\"button\" id=\"btnDel\" value=\"-\" onClick=\"RemoveRow('row_"+intLine+"');\"></center>";
114.        }
115.     
116.    document.frm_request.hdnMaxLine1.value = intLine;
117.     
118.}


Code (PHP)
01.<form id="frm_request" name="frm_request" method="post" action="request_result.php">
02. 
03.<input type="hidden" name="hdnMaxBoard" value="0">
04.<input type="hidden" name="hdnMaxLine1" value="0">
05.<input type="hidden" name="hdnMaxBoardStandard" value="0">
06. 
07.<input type="checkbox" name="group_boardLineItem" value="1" id="group_boardLineItem" onclick="showhide()"/>Board
08.<input name="btn_board" type="button" id="btn_board" class="button" value="+Add Board" onClick="CreateNewBoard(this)">
09.<br/><br/>
10. 
11.<div id="group_subItem" style="display:none">
12.################# ควรจะให้มัน รันตามบอร์ดที่เพิ่มปะคะ #################
13.<table id="tblBoard" class="gridtable" bgcolor="#f8f8f8">
14.<thead>
15.</thead>
16.<tbody>
17.</tbody>
18.</table>
19.</div>
20. 
21.<input type="checkbox" name="group_boardStandard" value="1" id="group_boardStandard" onclick="showhide()"/>Board Standard
22.<input name="btn_boardStandard" type="button" id="btn_boardStandard" class="button" value="+Add Board" onClick="CreateNewBoard(this)">
23.<br/><br/>
24.<div id="boardstandard" style="display:none">
25.<table id="tbl_boardstandard" class="gridtable" bgcolor="#f8f8f8">
26.<thead>
27.</thead>
28.<tbody>
29.</tbody>
30.</table>
31.</div>
32.<br/><input type="submit" name="submit" value="Save" class="button"/>
33.</form>




Tag : JavaScript

Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-05-22 13:11:03 By : unzeen View : 1631 Reply : 1
 

 

No. 1



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

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

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

ยากหน่อยน่ะครับ แต่เขียนได้ขนาดนี้แล้ว ผมว่าลองปรับแก้ไขเองไม่น่าจะยากครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-05-23 15:22:46 By : webmaster
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : จะเพิ่ม record เมื่อกด ปุ่ม แต่เวลาเพิ่ม ให้เพิ่มตามกลุ่มที่เพิ่มอะคะ ทำยังไงคะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 อัตราราคา คลิกที่นี่