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,027

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



 

จะเพิ่ม 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)
function getCustomBoardRows(i, type){
	//alert(type); ประเภทปุ่ม button มีสองประเภทคือ btn_board, btn_boardStandard
	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+'\')">';
}

function getStandBoardRows(i, type){
	//alert(type); ประเภทปุ่ม button มีสองประเภทคือ btn_board, btn_boardStandard
	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+'\')">';
}

function getHeadColumn(type){
	var customHead = new Array("ชื่อกระเบื้อง","ขนาด","จำนวน","หน่วย","ประเภทแผ่น","ขนาดแผ่นตัด","ราคา/หน่วย","ราคารวม","หมายเหตุ","");
	var standHead  = new Array("หมายเลขบอร์ด","ชื่อบอร์ด","ประเภทบอร์ด","จำนวนบอร์ด","จำนวนบอร์ด","หมายเหตุ","");
	return (type == "btn_board")? customHead : standHead; 
}

function CreateNewBoard(typeBoard){
	var typeBoard 	= typeBoard.id
	var field		= getHeadColumn(typeBoard);
	var allColumn	= (typeBoard=="btn_board")? 10:7;
	intBoard = parseInt(document.frm_request.hdnMaxBoard.value);
	intBoard++;
	alert(intBoard);
	//eval("document.getElementById('tblBoard_"+intBoard+"')");
########################## บรรทัดนี้เราต้อง Fix ค่าตาราง หมายเลขตารางป่าวคะ ###############################
########################## แต่เราไม่รู้ว่า ตรงฟอร์ม HTML เราจะให้เลขไปต่อท้ายหลังยังไงนะคะเช่น tblBoard_1 tblBoard_2 อย่างนี้นะคะ ######
	var tableBoard = (typeBoard=="btn_board")? document.getElementById("tblBoard") : document.getElementById("tbl_boardstandard");

	
	for(intRow=0;intRow<2;intRow++){
		if(intRow==0){
			var insertRow1	 	= tableBoard.insertRow(0);
			var Row1Cell1	 	= insertRow1.insertCell(0); //
			Row1Cell1.colSpan = allColumn;
			Row1Cell1.style.backgroundColor = "#A7C520";
			Row1Cell1.style.color = "black";
			Row1Cell1.innerHTML	= (typeBoard=="btn_board")? getCustomBoardRows(intBoard, typeBoard) : getStandBoardRows(intBoard, typeBoard); 
		}else{
			var insertRow2	 	= tableBoard.insertRow(intRow);
			for(intCol=0;intCol<allColumn;intCol++){
				var Row2Cell	 	= insertRow2.insertCell(intCol);
				Row2Cell.style.backgroundColor = "#F5F6D4";
				Row2Cell.innerHTML="<center>"+field[intCol]+"</center>";
			}
		}
	}
	CreateNewItem(typeBoard);// typeBoard --> btn_board, btn_boardStandard
	document.frm_request.hdnMaxBoard.value = intBoard; /*set ค่า  hdnMaxBoard*/
}

function CreateNewItem(type,board){
	alert(board);
	var intLine = parseInt(document.frm_request.hdnMaxLine1.value);
	intLine++;
	var theTableBoard = (type=="btn_board")? document.getElementById("tblBoard") : document.getElementById("tbl_boardstandard");
	var insertRow	 	= theTableBoard.insertRow(2);
	var intField = (type=="btn_board")? 10:7;
	for(var ii=0;ii<intField;ii++){
		eval("var RowCell"+(ii+1)+" = insertRow.insertCell("+ii+");");
	}
	if(type=="btn_board"){
		
		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
		//*** Create Option ***//
		CreateSelectOption("txtProductName_"+intLine,"productTiles"+intLine,intLine)
		
		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>";
		
		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>";
		
		RowCell4.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"2\" NAME=\"quantity_"+intLine+"\"  ID=\"quantity_"+intLine+"\"  class=\"inputtext_nfixw\" VALUE=\"\"></center>";
		
		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>";
		//*** Create Option ***//
		CreateSelectOption("unit_"+intLine,"unit_"+intLine,intLine)
		
		RowCell5.innerHTML = "<center><SELECT NAME=\"typepcs_"+intLine+"\" ID=\"typepcs_"+intLine+"\" class=\"inputtext_nfixw\" ></SELECT></center>";
		//*** Create Option ***//
		CreateSelectOption("typepcs_"+intLine,"typepcs_"+intLine,intLine)
		
		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>";
		
		RowCell7.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"priceperunit_"+intLine+"\" ID=\"priceperunit_"+intLine+"\"   class=\"inputtext_nfixw\" VALUE=\"\"></center>";
		
		RowCell8.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"pricetotal_"+intLine+"\" ID=\"pricetotal_"+intLine+"\"   class=\"inputtext_nfixw\" VALUE=\"\"></center>";
		
		RowCell9.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"15\" NAME=\"remark_"+intLine+"\" ID=\"remark_"+intLine+"\"   class=\"inputtext_nfixw\" VALUE=\"\"></center>";
		
		RowCell10.innerHTML = "<center><input name=\"btnDel\" type=\"button\" id=\"btnDel\" value=\"-\" onClick=\"RemoveRow('row_"+intLine+"');\"></center>";
		
	}else{

		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>";
		//*** Create Option ***//
		CreateSelectOption("txtProductName_"+intLine,"productTiles"+intLine,intLine)
		
		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>";
		
		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>";
		
		RowCell4.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"2\" NAME=\"quantity_"+intLine+"\"  ID=\"quantity_"+intLine+"\"  class=\"inputtext_nfixw\" VALUE=\"\"></center>";
		
		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>";
		//*** Create Option ***//
		CreateSelectOption("unit_"+intLine,"unit_"+intLine,intLine)
		
		RowCell5.innerHTML = "<center><SELECT NAME=\"typepcs_"+intLine+"\" ID=\"typepcs_"+intLine+"\" class=\"inputtext_nfixw\" ></SELECT></center>";
		//*** Create Option ***//
		CreateSelectOption("typepcs_"+intLine,"typepcs_"+intLine,intLine)
		
		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>";
		
		RowCell7.innerHTML = "<center><input name=\"btnDel\" type=\"button\" id=\"btnDel\" value=\"-\" onClick=\"RemoveRow('row_"+intLine+"');\"></center>";
		}
	
	document.frm_request.hdnMaxLine1.value = intLine;
	
}


Code (PHP)
<form id="frm_request" name="frm_request" method="post" action="request_result.php">

<input type="hidden" name="hdnMaxBoard" value="0">
<input type="hidden" name="hdnMaxLine1" value="0">
<input type="hidden" name="hdnMaxBoardStandard" value="0">

<input type="checkbox" name="group_boardLineItem" value="1" id="group_boardLineItem" onclick="showhide()"/>Board
<input name="btn_board" type="button" id="btn_board" class="button" value="+Add Board" onClick="CreateNewBoard(this)">
<br/><br/>

<div id="group_subItem" style="display:none">
################# ควรจะให้มัน รันตามบอร์ดที่เพิ่มปะคะ #################
<table id="tblBoard" class="gridtable" bgcolor="#f8f8f8">
<thead>
</thead>
<tbody>
</tbody>
</table>
</div>

<input type="checkbox" name="group_boardStandard" value="1" id="group_boardStandard" onclick="showhide()"/>Board Standard
<input name="btn_boardStandard" type="button" id="btn_boardStandard" class="button" value="+Add Board" onClick="CreateNewBoard(this)">
<br/><br/>
<div id="boardstandard" style="display:none">
<table id="tbl_boardstandard" class="gridtable" bgcolor="#f8f8f8">
<thead>
</thead>
<tbody>
</tbody>
</table>
</div>
<br/><input type="submit" name="submit" value="Save" class="button"/>
</form>




Tag : JavaScript







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

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 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 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

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