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 > สอบถามเรื่องการ clone ซึ่งมี Autocomplete ด้วย คือจะสร้าง dropdownlist ค่าโชว์ขึ้นนะคะ แต่เวลาบันทึกลง DB สินค้าชิ้นที่2 ค่าใน dropdown นั้นๆไม่บันทึกค่า



 

สอบถามเรื่องการ clone ซึ่งมี Autocomplete ด้วย คือจะสร้าง dropdownlist ค่าโชว์ขึ้นนะคะ แต่เวลาบันทึกลง DB สินค้าชิ้นที่2 ค่าใน dropdown นั้นๆไม่บันทึกค่า

 



Topic : 125874



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



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



Code (PHP)
<form action="" id="itemsForm">
                           
                              <table id="itemsTable" class="general-table">
                                    <thead>
                                    <tr>
								
                                        <th></th>
                                        <th>รหัสสินค้า</th>
                                        <th>ชื่อสินค้า</th>
                                        <th>ประเภท</th>
                                        <th>ราคา</th>
                                        <th>จำนวน</th>
                                        <th>ส่วนลด</th>
                                        

                                    </tr>
                                    </thead>
                                    <tbody>
                                        <tr class="item-row">
                                            <td></td>
                                        <td><input name="Scode[]" value="" class="tInput" id="Scode" tabindex="1"/> </td>
                                        <td><input name="Sname[]" value="" class="tInput" id="Sname" /></td>
										<td><select name="TypeScode[]" class="tInput" id="TypeScode" tabindex="2"><option value=""> -- ประเภท --</option><option value="ล้อเป็น">ล้อเป็น</option><option value="ล้อตาย">ล้อตาย</option><option value="หูลาก">หูลาก</option><option value="ล้อเปล่า">ล้อเปล่า</option></select></td>
                                        <td><input name="Price[]" value="" class="tInput" tabindex="3" id="Price" OnKeyPress="return chkNumber(this);" /></td>
                                        <td><input name="Quantity[]" value="" class="tInput" id="Quantity" tabindex="4" OnKeyPress="return chkNumber(this);" /> </td>
                                        <td><input name="Discount[]" value="" class="tInput" id="Discount" tabindex="5" OnKeyPress="return chkNumber(this)" /></td>
                                        </tr>
                                    </tbody>
                                </table>

                          </form>

                            <a href="#" id="addRow" class="button-clean large"><span> <img src="../autocomplete/images/icon-plus.png" alt="Add" title="Add Row" /> Add Item</span></a>




Scode และ Sname ได้จากการ Autocomplete มาจากไฟล์ item-data3.php

Code (JavaScript)
$(document).ready(function(){

    // Use the .autocomplete() method to compile the list based on input from user
    $('#Scode').autocomplete({
        source: '../autocomplete/data/item-data3.php',
        minLength: 1,
        select: function(event, ui) {
            var $itemrow = $(this).closest('tr');
                    // Populate the input fields from the returned values
                    $itemrow.find('#Scode').val(ui.item.Scode);
                    $itemrow.find('#Sname').val(ui.item.Sname);
		     $itemrow.find('#TypeScode').val(ui.item.TypeScode)
                    // Give focus to the next input field to recieve input from user
					
					$('#Price').focus();
					$('#Quantity').focus();
					$('#Discount').focus();
					
					

            return false;
	    }
    // Format the list menu output of the autocomplete
    }).data( "autocomplete" )._renderItem = function( ul, item ) {
        return $( "<li></li>" )
            .data( "item.autocomplete", item )
            .append( "<a>" + item.Scode + " - " + item.Sname + "</a>" )
            .appendTo( ul );
    };

    // Get the table object to use for adding a row at the end of the table
    var $itemsTable = $('#itemsTable');

    // Create an Array to for the table row. ** Just to make things a bit easier to read.
    var rowTemp = [
        '<tr class="item-row">',
            '<td><a id="deleteRow"><img src="../autocomplete/images/icon-minus.png" alt="Remove Item" title="Remove Item"></a></td>',
            '<td><input name="h_item_id[]" type="hidden" id="h_item_id[]" value="" /><input name="Scode[]" class="tInput" value="" id="Scode" /> </td>',
            '<td><input name="Sname[]" class="tInput" value="" id="Sname"  readonly="readonly" /></td>',
            '<td><select name="typeScode[]"  class="tInput" id="typeScode"><option value=""> -- ประเภท --</option><option value="ล้อเป็น">ล้อเป็น</option><option value="ล้อตาย">ล้อตาย</option><option value="หูลาก">หูลาก</option><option value="ล้อเปล่า">ล้อเปล่า</option></select></td>',
			'<td><input name="Price[]" value="" class="tInput" id="Price" OnKeyPress="return chkNumber(this);" /></td>',
            '<td><input name="Quantity[]" value="" class="tInput" id="Quantity" OnKeyPress="return chkNumber(this);" /> </td>',
            '<td><input name="Discount[]" value="" class="tInput" id="Discount" OnKeyPress="return chkNumber(this);"/></td>',
			'</tr>'
    ].join('');

    // Add row to list and allow user to use autocomplete to find items.
    $("#addRow").bind('click',function(){

        var $row = $(rowTemp);

        // save reference to inputs within row
        var $Scode 	        = $row.find('#Scode');
        var $Sname 	        = $row.find('#Sname');
        var $TypeScode 	    = $row.find('#TypeScode');
		var $Price	        = $row.find('#Price');
        var $Quantity	    = $row.find('#Quantity');
		var $Discount 	    = $row.find('#Discount');
		


        if ( $('#Scode:last').val() !== '' ) {

            // apply autocomplete widget to newly created row
            $row.find('#Scode').autocomplete({
                source: '../autocomplete/data/item-data3.php',
                minLength: 1,
                select: function(event, ui) {
                    $Scode.val(ui.item.Scode);
                    $Sname.val(ui.item.Sname);
					
                    // Give focus to the next input field to recieve input from user
                    $TypeScode.focus();
					$Price.focus();
					$Quantity.focus();
					$Discount.focus();
					

                    return false;
                }
            }).data( "autocomplete" )._renderItem = function( ul, item ) {
                return $( "<li></li>" )
                    .data( "item.autocomplete", item )
                    .append( "<a>" + item.Scode + " - " + item.Sname + "</a>" )
                    .appendTo( ul );
            };
            // Add row after the first row in table
            $('.item-row:last', $itemsTable).after($row);
            $($Scode).focus();

        } // End if last Scode input is empty
        return false;
    });

    $('#Scode').focus(function(){
        window.onbeforeunload = function(){ return "ทำรายการ PO"; };
    });

}); // End DOM


	// Remove row when clicked
	$("#deleteRow").live('click',function(){
		$(this).parents('.item-row').remove();
        // Hide delete Icon if we only have one row in the list.
        if ($(".item-row").length < 2) $("#deleteRow").hide();
	});
	



26-12-59-1

ลองบันทึกลง DB โดยการเพิ่มสินค้า2รายการ ทั้ง2ครั้ง มีแค่รายการแรกที่ประเภทสินค้าขึ้น
26-12-59-2



Tag : PHP, JavaScript







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2016-12-26 17:23:59 By : bsaranya View : 930 Reply : 3
 

 

No. 1



โพสกระทู้ ( 5,105 )
บทความ ( 4 )

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

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


การทำงาน คลิก addRow ได้ select option สร้าง name="typeScode[]" เป็นแบบ array ...
ต้องดู code ตอนส่งค่า กับ รับค่า แล้วละครับ ว่าส่งด้วยอะไร รับแบบไหน เพิ่มเติมด้วยครับ

หรือในหน้าที่รับค่าไปบันทึกลอง Debug ตัวแปร echo $_POST['typeScode'] ดู
ตอนรับค่าลืม count หรือเปล่า....

Code
$data = $_POST['typeScode']; $len = count($data); for($x=0 ; $x < $len ; $x++){ echo "$data[$x]"."<br />"; }









ประวัติการแก้ไข
2016-12-27 11:00:12
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-12-27 10:54:36 By : apisitp
 


 

No. 2



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



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

หน้า savePO.php
Code (PHP)
foreach($_POST["Scode"] as $index =>$sT){ 
$tsT = $_POST["TypeScode"][$index];
$pT = $_POST["Price"][$index];
$qT = $_POST["Quantity"][$index];
$dT = $_POST["Discount"][$index];
$suT  = $pT*$qT;
$tT = $suT-$dT;
$qOrder = "INSERT INTO `po_order` (Scode,TypeScode,Price,Quantity,Discount,Summary,Total,id_po)
             VALUES ('$sT','$tsT','$pT','$qT','$dT','$suT','$tT','$maxPo')";

mysql_query($qOrder);

}


สมมติเลือก
สินค้าชิ้นที่ 1 ประเภทล้อตาย
สินค้าชิ้นที่ 2 ประเภทล้อเป็น

echo "<script type='text/javascript'>alert('$tsT');window.location='showPO.php'</script>";
จะขึันแค่อันเดียวคือ ล้อตาย

Code (PHP)
$data = $_POST['typeScode'];
$len = count($data);
for($x=0 ; $x < $len ; $x++){
  echo "$data[$x]"."<br />";
}

จะขึันแค่อันเดียวคือ ล้อตาย
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-12-28 10:59:43 By : bsaranya
 

 

No. 3



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



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

ได้แล้ว ขอบคุณค่ะ


ประวัติการแก้ไข
2017-01-04 14:11:32
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2017-01-04 14:05:48 By : bsaranya
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : สอบถามเรื่องการ clone ซึ่งมี Autocomplete ด้วย คือจะสร้าง dropdownlist ค่าโชว์ขึ้นนะคะ แต่เวลาบันทึกลง DB สินค้าชิ้นที่2 ค่าใน dropdown นั้นๆไม่บันทึกค่า
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 00
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 อัตราราคา คลิกที่นี่