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 > PHP > PHP Forum > ช่วยแนะนำตัวอย่างในการรวมค่าใน textfield ด้วยครับ กรณีมีการเพิ่ม field ขึ้นมาใหม่



 

ช่วยแนะนำตัวอย่างในการรวมค่าใน textfield ด้วยครับ กรณีมีการเพิ่ม field ขึ้นมาใหม่

 



Topic : 131015



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



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




ขอความช่วยเหลือเรื่องแนวคิดการรวมค่าด้วยครับในกรอบสีแดง เพื่อแสดงลงในกรอบสีเขียว พอดีผมโมโค๊ดจากกระทู้นี้ >> https://www.thaicreate.com/php/forum/002630.html
ที่เป็นการกดเพิ่มแถวเพื่อใช้กรอกข้อมูลครับ

ต้องการรวมค่าในกรอบสีแดง เพื่อแสดงลงในกรอบสีเขียว

จากโค๊ดนี้ครับ
Code (JavaScript)
	function CreateNewRow()
	{
		var intLine = parseInt(document.frmMain.hdnMaxLine.value);
		intLine++;
			
		var theTable = document.all.tbExp
		var newRow = theTable.insertRow(theTable.rows.length)
		newRow.id = newRow.uniqueID
		
		var item1 = 1
		var newCell
		
		//*** Column 1 ***//
		newCell = newRow.insertCell(0)
		newCell.id = newCell.uniqueID
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<select class=\"form-control\" NAME=\"prodname_"+intLine+"\" id=\"prodname_"+intLine+"\">\
				      		<option value=\"\">--- กรุณาเลือก ---</option>\
				      		<?php $post_data1 = $data->tran_pageprodname();
	  						foreach ($post_data1 as $post1) {
						    echo "<option value= '".$post1["Prod_desc"]."'>".$post1["Prod_desc"]."</option>";
							}?></select>"

		//*** Column 2 ***//
		newCell = newRow.insertCell(1)
		newCell.id = newCell.uniqueID
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<select class=\"form-control\" NAME=\"prodtype_"+intLine+"\" id=\"prodtype_"+intLine+"\">\
				      		<option value=\"\">--- กรุณาเลือก ---</option>\
				      		<?php $post_data1 = $data->tran_pagetypename();
	  						foreach ($post_data1 as $post1) {
						    echo "<option value=".$post1["Prod_type_id"].">".$post1["Prod_type_desc"]."</option>";
						     } ?></select>";		
		
		//*** Column 3 ***//
		newCell = newRow.insertCell(2)
		newCell.id = newCell.uniqueID
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<input type=\"number\" class=\"form-control\" NAME=\"proprice_"+intLine+"\" id=\"proprice_"+intLine+"\">";


		newCell = newRow.insertCell(3)
		newCell.id = newCell.uniqueID
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<input type=\"number\" class=\"form-control\" NAME=\"proqty_"+intLine+"\" id=\"proqty_"+intLine+"\">";	

		newCell = newRow.insertCell(4)
		newCell.id = newCell.uniqueID
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<input type=\"number\" class=\"form-control\" NAME=\"prototal_"+intLine+"\" id=\"prototal_"+intLine+"\">";

		$(document).ready(function() {
	      	$("#prodtype_"+intLine+"").change(function() {
	          	var name = $("#prodname_"+intLine+"").val();
	          	var type = $("#prodtype_"+intLine+"").val();
	          	var jsonObj = {"prodname": name, "prodtype": type}
	          	$.ajax({
	             	type: "POST",
	            	url: "./lib/getform2.php",
	             	data: jsonObj,
	             	success: function(result) {
	            	//alert(result);
	            	$("#proprice_"+intLine+"").val(result);
	            	//alert($('#txtval').val());
	             	}
	           });
	      	});
	      	$("#proqty_"+intLine+"").change(function() {
	          	var qty = $("#proqty_"+intLine+"").val();
	          	var prodprice = $("#proprice_"+intLine+"").val();
	          	var total = prodprice*qty;
	          	$("#prototal_"+intLine+"").val(total);
	      	});
	      	var data_arr = [];
    	});		
			
		document.frmMain.hdnMaxLine.value = intLine;
	}
	


	function RemoveRow()
	{
		intLine = parseInt(document.frmMain.hdnMaxLine.value);
		if(parseInt(intLine) > 0)
		{
				theTable = (document.all) ? document.all.tbExp : 
				document.getElementById("tbExp")
				theTableBody = theTable.tBodies[0];
				theTableBody.deleteRow(intLine);
				intLine--;
				document.frmMain.hdnMaxLine.value = intLine;
		}	
	}




Tag : PHP, HTML, Ajax, jQuery







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2018-05-10 09:55:08 By : thitikub View : 570 Reply : 3
 

 

No. 1



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

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

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

Code (JavaScript)
var sumtotal=0;

$("#prototal_"+intLine+"").change(function(){
    sumtotal = sumtotal+parseInt($(this).val());
});

$("#your_summary_field").val(sumtotal); //เปลี่ยนชื่อช่องรวมเอาเองน่ะครับ







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-05-10 10:41:17 By : mongkon.k
 


 

No. 2



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



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


ยังไม่ได้อยู่ดีครับ ค่าที่แสดงออกมาใน text field มันแสดงเป็น 0 ครับ

Code (JavaScript)
function CreateNewRow()
	{
		var intLine = parseInt(document.frmMain.hdnMaxLine.value);
		intLine++;
			
		var theTable = document.all.tbExp
		var newRow = theTable.insertRow(theTable.rows.length)
		newRow.id = newRow.uniqueID
		
		var item1 = 1
		var newCell
		
		//*** Column 1 ***//
		newCell = newRow.insertCell(0)
		newCell.id = newCell.uniqueID
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<select class=\"form-control\" NAME=\"prodname_"+intLine+"\" id=\"prodname_"+intLine+"\">\
				      		<option value=\"\">--- กรุณาเลือก ---</option>\
				      		<?php $post_data1 = $data->tran_pageprodname();
	  						foreach ($post_data1 as $post1) {
						    echo "<option value= '".$post1["Prod_desc"]."'>".$post1["Prod_desc"]."</option>";
							}?></select>"

		//*** Column 2 ***//
		newCell = newRow.insertCell(1)
		newCell.id = newCell.uniqueID
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<select class=\"form-control\" NAME=\"prodtype_"+intLine+"\" id=\"prodtype_"+intLine+"\">\
				      		<option value=\"\">--- กรุณาเลือก ---</option>\
				      		<?php $post_data1 = $data->tran_pagetypename();
	  						foreach ($post_data1 as $post1) {
						    echo "<option value=".$post1["Prod_type_id"].">".$post1["Prod_type_desc"]."</option>";
						     } ?></select>";		
		
		//*** Column 3 ***//
		newCell = newRow.insertCell(2)
		newCell.id = newCell.uniqueID
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<input type=\"number\" class=\"form-control\" NAME=\"proprice_"+intLine+"\" id=\"proprice_"+intLine+"\">";


		newCell = newRow.insertCell(3)
		newCell.id = newCell.uniqueID
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<input type=\"number\" class=\"form-control\" NAME=\"proqty_"+intLine+"\" id=\"proqty_"+intLine+"\">";	

		newCell = newRow.insertCell(4)
		newCell.id = newCell.uniqueID
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<input type=\"number\" class=\"form-control\" NAME=\"prototal_"+intLine+"\" id=\"prototal_"+intLine+"\">";

		$(document).ready(function() {
	      	$("#prodtype_"+intLine+"").change(function() {
	          	var name = $("#prodname_"+intLine+"").val();
	          	var type = $("#prodtype_"+intLine+"").val();
	          	var jsonObj = {"prodname": name, "prodtype": type}
	          	$.ajax({
	             	type: "POST",
	            	url: "./lib/getform2.php",
	             	data: jsonObj,
	             	success: function(result) {
	            	//alert(result);
	            	$("#proprice_"+intLine+"").val(result);
	            	//alert($('#txtval').val());
	             	}
	           });
	      	});
	      	$("#proqty_"+intLine+"").change(function() {
	          	var qty = $("#proqty_"+intLine+"").val();
	          	var prodprice = $("#proprice_"+intLine+"").val();
	          	var total = prodprice*qty;
	          	$("#prototal_"+intLine+"").val(total);
	      	});
	      	
	      	var sumtotal=0;
			$("#prototal_"+intLine+"").change(function(){
			    sumtotal = sumtotal+parseInt($(this).val());
			});
			$("#ordertotal").val(sumtotal);
    	});		
			
		document.frmMain.hdnMaxLine.value = intLine;
	}



ประวัติการแก้ไข
2018-05-10 13:47:40
2018-05-10 13:48:15
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-05-10 13:46:19 By : thitikub
 

 

No. 3



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

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

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

โทษครับ ผมผิดเอง เอาใหม่
Code (JavaScript)
var sumtotal=0;

$("#prototal_"+intLine+"").change(function(){
    //var obj= $(this);
    $("#prototal_"+intLine+"").each(function(index,val){
      sumtotal = sumtotal+parseInt(val);
    });
    
});

$("#your_summary_field").val(sumtotal); //เปลี่ยนชื่อช่องรวมเอาเองน่ะครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-05-10 13:56:57 By : mongkon.k
 

   

ค้นหาข้อมูล


   
 

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