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 > ช่วยหนูด้วยคะ autocomplete+ autofill +enter next cell



 

ช่วยหนูด้วยคะ autocomplete+ autofill +enter next cell

 



Topic : 110808



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



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




ช่วยด้วยคะ คือหนู ทำautocomplete และ autofill หลายจุด ใน1 form แล้วมันไม่ได้อะคะ พิมพ์ไป ก็ไม่เกิดไรขึ้นสักอัน พอแอดrowใหม่ enter ก็ไม่เลื่อนcell ให้ แล้วก็ไม่มีautocomplete autofill ตามติดมาด้วยอะคะ ใครพอมีโค้ดตัวอย่างสอนไหมคะ


Code (PHP)
<?php
    include_once "master.action.php";
    include_once "../../include/function.php";     
    include_once "../../include/template/index.tpl.php";   
?>
<script type="text/javascript" src="../../dialog/dialog.js"></script>
<link type="text/css" rel="stylesheet" href="../../include/js/tabber/example.css"/>
<script type="text/javascript" src="../../include/js/tabber/tabber.js"></script>
<script type="text/javascript" src="../../include/autocomplete/autocomplete.js"></script>  
<link rel="stylesheet" href="../../include/autocomplete/autocomplete.css"  type="text/css"/> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript">

    $(function(){
        $("#save").click(function(){
            if (validate()){
                 var validate_data = chk_company();
                 var arr_validate_data = validate_data.split('|');

                 if(Trim(arr_validate_data['2'])=="Y"){
                    alert('Company code : '+arr_validate_data['1']+' already exist');
                    return false;
                 }else{
                    page_submit("index.php?action=master.php", "save")
                 }
            }
        });

        $("#reset").click(function(){
            page_submit("index.php?action=master.php")
        });

        $("#back").click(function(){
            page_submit("index.php?action=master_list.php")
        });

        $("#div").css("display", "block");
    });
    
      $("#Delete").click(function(){

            var data_company = $(this).attr("value");
            var arr_company = data_company.split('|');

            $("#id").val(arr_company['0']);

            if (confirm("<?=LABEL_ALERT_DELETE?> Company Code : "+arr_company['1'])) {
                page_submit("index.php?action=master.php", "delete");
            }
        });

        $("#search").click(function(){
            $("#page").val(1);
            page_submit("index.php?action=master.php", "search");
        });


    function chk_company(){
        var result="";
        var company_code = $("#company_code").val();
        var company_id = $("#id").val();
        var mode = $("#act").val();
        
        $.ajax({
            url: "../../include/chk_duplicate.php",
            type: "GET",
            async: false,
            data: "type=company&mode="+mode+"&company_code="+company_code+"&id="+company_id,
            success: function(output) {
                result = output;
            }
        });
        return result;
    }
</script>
<script language="javascript">
    $(document).ready(function() {
        $(window).keydown(function(event){
            if(event.keyCode == 13) {
                event.preventDefault();
                return false;
            }
        });
        $(document).on('keyup',"input[name*='quantity_']", function () {
         var sum = 0;
         //iterate through each textboxes and add the values
         $("input[name*='quantity_']").each(function () {
             //add only if the value is number
             if (!isNaN(this.value) && this.value.length != 0) {
                 sum += parseFloat(this.value);
             }

         });
         $("input[name='sum']").val(sum.toFixed(2));
     });

     
         $("#CheckAll").click(function () {
         $('input:checkbox').not(this).prop('checked',this.checked);  });
         
         $("#btnDel").click(function () {
         $('input:checkbox').not(this).prop('checked',this.checked);  });
    });
	function CreateNewRow()
	{
		var intLine = parseInt(document.frmMain.hdnMaxLine.value);
		intLine++;
			
		var theTable = document.getElementById("tbExp");
		var newRow = theTable.insertRow(theTable.rows.length)
              
		newRow.id = newRow.uniqueID

		var newCell
		
                //*** Column 7 ***//
		newCell = newRow.insertCell(0);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"CHECKBOX\"  SIZE=\"15\" NAME=\"chkbox_"+intLine+"\" ID=\"chkbox_"+intLine+"\" ></center>";
                
		//*** Column 1 ***//
		newCell = newRow.insertCell(1);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center>"+intLine+"</center>";

		//*** Column 2 ***//
		newCell = newRow.insertCell(2);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"25\" NAME=\"materialcode_"+intLine+"\" ID=\"materialcode_"+intLine+"\"  VALUE=\"\"></center>";
		
		//*** Column 3 ***//
		newCell = newRow.insertCell(3);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"25\" NAME=\"materialname_"+intLine+"\"  ID=\"materialname_"+intLine+"\" VALUE=\"\"></center>";
		
		//*** Column 4 ***//
		newCell = newRow.insertCell(4);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"25\" NAME=\"locationreceive_"+intLine+"\"  ID=\"locationreceive_"+intLine+"\" VALUE=\"\"></center>";
                
                //*** Column 5 ***//
		newCell = newRow.insertCell(5);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"25\" NAME=\"quantity_"+intLine+"\"  ID=\"quantity_"+intLine+"\" VALUE=\"\"></center>";
                
                //*** Column 6 ***//
		newCell = newRow.insertCell(6);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"25\" NAME=\"unit_"+intLine+"\"  ID=\"unit_"+intLine+"\" VALUE=\"\"></center>";
                
                
		

		//*** Create Option ***//
		//CreateSelectOption("Column5_"+intLine)
		
		document.frmMain.hdnMaxLine.value = intLine;
	}
	
	function RemoveRow()
	{
   
            var count_checked = $("input[type='checkbox']:checked").length; // count the checked
		if(count_checked == 0) {
			alert("Please select a product(s) to delete.");
			return false;
		}
		if(count_checked >=1) {
                    alert("You want to delete this product(s).");
                        $("input[name*='chkbox_']:checked").parents("tr").remove();                     
                     
		} 
		  
	} 
        
        
//         function setNextFocus(objId){
//        if (event.keyCode == 13){
//            var obj=document.getElementById(objId);
//            if (obj){
//                obj.focus();
//            }
//        }
//    }
</script>
<script type="text/javascript">
    $(function() {
        $('input:text:first').focus();
        var $inp = $('input:text');
        $inp.bind('keydown', function(e) {
            //var key = (e.keyCode ? e.keyCode : e.charCode);
            var key = e.which;
            if (key == 13) {
                e.preventDefault();
                var nxtIdx = $inp.index(this) + 1;
                $(":input:text:eq(" + nxtIdx + ")").focus();
            }
        });
       

    });
</script>

<script type="text/javascript">
function requester_autocom(autoObj,showObj){
	var mkAutoObj=autoObj; 
	var mkSerValObj=showObj; 
	new Autocomplete(mkAutoObj, function() {
		this.setValue = function(id) {		
			document.getElementById(mkSerValObj).value = id;
		}
		if ( this.isModified )
			this.setValue("");
		if ( this.value.length < 1 && this.isNotClick ) 
			return ;	
//		return "gdata.php?q=" +encodeURIComponent(this.value);
		return "gdata.php?q=" +this.value;
    });	
}	
 
// การใช้งาน
// make_autocom(" id ของ input ตัวที่ต้องการกำหนด "," id ของ input ตัวที่ต้องการรับค่า");
requester_autocom("requester","requester_id");
</script>

<script type="text/javascript">
function location_autocom(autoObj,showObj){
	var mkAutoObj=autoObj; 
	var mkSerValObj=showObj; 
	new Autocomplete(mkAutoObj, function() {
		this.setValue = function(id) {		
			document.getElementById(mkSerValObj).value = id;
		}
		if ( this.isModified )
			this.setValue("");
		if ( this.value.length < 1 && this.isNotClick ) 
			return ;	
		return "locationdata.php?q=" +encodeURIComponent(this.value);
//		return "locationdata.php?q="+this.value;
    });	
}	
 
// การใช้งาน
// make_autocom(" id ของ input ตัวที่ต้องการกำหนด "," id ของ input ตัวที่ต้องการรับค่า");
location_autocom("locationreceive_1","locationreceive_id_1");
</script>

<table width="100%" border-style="solid">
    <td>
        <!--R-->
        <table width="85%"  >
      <tr>
         <td   align="left" style="padding-right:5px;padding-left:10px"><?=LABEL_CODE?> :</td>
         <td><input type="text" maxlength="12" name="doc_num" id="doc_num" style="width: 200px;" autofocus value="" onKeyDown="setNextFocus('doc_date');"/></td> 
      <td>
<!--          <button id="search" style="width:50px;height:20px; float:left; background-color:#A0C0FF;border-color:#007ED1" class="input-button">
              <img src="../../images/find.png"/></button>-->
      </td>
      </tr>
      <tr>
        <td   align="left" style="padding-right:5px;padding-left:10px"><?=LABEL_DOC_DATE?> :</td>
        <td>
            <!--<span style="width: 200px"  type="calendar"  name="doc_date" id="doc_date"  required="false" onKeyDown="setNextFocus('requester');" value="<?//= $_REQUEST["doc_date"] ?>" img="../../images/calendar.png"></span>-->
            <input type="date" name="doc_date" id="doc_date"  style="width: 200px"  value="" onKeyDown="setNextFocus('requester');"/>
        </td>
      </tr>
    </table>
    </td>
    <!--L-->
    <td>
 
        <table width="85%">
            <tr>
       <td  align="left" style="padding-right:5px"><?=LABEL_REQUESTER?> :</td>
         <td><input type="text" name="requester" id="requester" style="width: 200px;" value=""   onKeyDown="setNextFocus('ref_doc');" /></td> 
           <td> <input name="requester_id" type="hidden" id="requester_id" value="" />  </td>
            </tr>   
 
      <tr>
         <td  align="left" style="padding-right:5px" ><?=LABEL_REF_DOC?> :</td>
         <td><textarea name="ref_doc" id="ref_doc" rows="1" cols="30" onKeyDown="setNextFocus('objecttive');"  > <?=$data["ref_doc"]?> </textarea></td>
      </tr>
    </table>
    </td>
       <tr>
      <table width="100%"  >
      <td  valign="top" style="padding-right:5px;padding-left:10px"><?=LABEL_OBJECTIVE?> :</td>
         <td><textarea name="objecttive" id="objecttive" rows="3" cols="128"> <?=$data["objective"]?></textarea></td>
      </table>
     </tr>
</table>
<hr>
<table width="100%"  > 
       <td width="10%" align="center">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
       <td width="10%" align="center">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
       <td width="10%" align="center">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
       <td width="10%" align="center">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
       <td width="10%" align="center">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
       <td width="10%" align="center"><input type="hidden" name="hdnMaxLine" value="20"></td>
       <td width="10%" align="right"> <input  name="btnAdd" type="button" id="btnAdd"  value="ADD" onclick="CreateNewRow()" style="font-size:10; height:20px;width:50px; color:#000000; background:#CCFFCC;" > เพิ่มรายการ</td>
       <td width="10%" align="right"><input  name="btnDel" type="button" id="btnDel" value="DEL" onclick="RemoveRow()" style="font-size:10; height:20px;width:50px; color:#000000; background:#CCFFCC;"> ลบรายการ&nbsp;&nbsp;&nbsp;</td> 
      </table>
<div id="table-wrapper">
  <div id="table-scroll">
     <table id="tb1" width="100%"  class="data-table">
         <thead>
                    <tr>
                        <td width="5%" align="center"><input name="CheckAll" type="checkbox" id="CheckAll" value="" onclick="CheckAll()" ></td>
                        <td width="5%" align="center"><?=LABEL_NO?></td>
                        <td width="10%" align="center"><?=LABEL_MATERIAL_CODE?></td>
                        <td width="10%" align="center"><?=LABEL_MATERIAL_NAME?></td>
                        <td width="10%" align="center"><?=LABEL_LOCATION?></td>
                        <td width="10%" align="center"><?=LABEL_QUANTITY?></td>
                        <td width="10%" align="center"><?=LABEL_UNIT?></td>     
                        
                    </tr>
                </thead>

                <tbody name="tbExp" id="tbExp"  style="overflow-y:scroll; height:50px;" width="100%" border="0" cellpadding="0" cellspacing="0" >      
     
                    <? for($i=1;$i<=20;) { ?>
                    
                    <tr>
                        <td align="center" ><input name="chkbox_<?=$i;?>" id="chkbox_<?=$i;?>" type="checkbox"/></td>
                        <td align="center"><?=$i;?></td>
                        <td align="center" ><input name="materialcode_<?=$i;?>" id="materialcode_<?=$i;?>" type="text" style="width: 165px;" value="" /></td>
                        <td align="center" ><input name="materialname_<?=$i;?>" id="materialname_<?=$i;?>" type="text" style="width: 165px;" value="" /></td>
                        <td align="center" ><input name="locationreceive_<?=$i;?>" id="locationreceive_<?=$i;?>" type="text" style="width: 165px;" value="" /></td>
                        <td align="center" ><input name="quantity_<?=$i;?>" id="quantity_<?=$i;?>" type="text"  style="width: 165px;" value="" /></td>
                        <td align="center" ><input name="unit_<?=$i;?>" id="unit_<?=$i;?>" type="text" style="width: 165px;" value="" /></td>
                        <td> <input name="locationreceive_id_<?=$i;?>" type="hidden" id="locationreceive_id_<?=$i;?>" value="" />  </td>               
     </tr>
                    
                    
                <? $i++;} ?>
              
                </tbody>            
 
            </table>
       </div>
</div>
       <table width="100%" class="tr_header1">
                     <tr>
                        <td width="5%" align="center"></td>
                        <td width="5%" align="center"></td>
                        <td width="10%" align="center"></td>
                        <td width="10%" align="center"></td>
                        <td width="10%" align="center"><?=LABEL_SUM?>&nbsp;&nbsp;&nbsp;&nbsp;= </td>
                        <td width="10%" align="center"><input name="sum" id="sum" type="text"  readonly class="disabled" style="width:162px;" value="" /></td>
                        <td width="10%" align="center"></td>     
                        
                    </tr>
       </table>
<script type="text/javascript">
requester_autocom("requester","requester_id");
location_autocom("locationreceive_1","locationreceive_id_1");
</script>



     




Tag : PHP, HTML/CSS, JavaScript, Ajax, jQuery







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2014-08-22 15:16:58 By : nornatt View : 1224 Reply : 5
 

 

No. 1



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



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


Code (PHP)
<?php
header("Content-type:text/html; charset=UTF-8"); 
header("Cache-Control: no-store, no-cache, must-revalidate"); 
header("Cache-Control: post-check=0, pre-check=0", false); 
// เชื่อมต่อฐานข้อมูล
$link=mysql_connect("localhost","root","1") or die("error".mysql_error());
mysql_select_db("inventory",$link);
mysql_query("SET NAMES UTF8");
//mysql_query("SET character_set_results=UTF8");
//mysql_query("SET character_set_client=UTF8");
//mysql_query("SET character_set_connection=UTF8");
//mb_internal_encoding('UTF-8');
//mb_http_output('UTF-8');
//mb_http_input('UTF-8');
//mb_language('uni');
//mb_regex_encoding('UTF-8');
//ob_start('mb_output_handler');
//setlocale(LC_ALL, 'th_TH');

//$q = urldecode($_GET["q"]);
//$q= iconv('utf-8', 'tis-620', $_GET['test']);
//$q = $_GET["q"];
$pagesize = 10; // จำนวนรายการที่ต้องการแสดง
$table_db=" tb_employee"; // ตารางที่ต้องการค้นหา
$find_field="employee_name"; // ฟิลที่ต้องการค้นหา
$sql = "select * from $table_db where locate('$q', $find_field) > 0 order by locate('$q', $find_field), $find_field limit $pagesize";
$results = mysql_query($sql);
while ($row = mysql_fetch_array( $results )) {
$id = $row["employee_code"]; // ฟิลที่ต้องการส่งค่ากลับ
$name =$row["employee_name"]; // ฟิลที่ต้องการแสดงค่า
// ป้องกันเครื่องหมาย '
$name = str_replace("'", "'", $name);
// กำหนดตัวหนาให้กับคำที่มีการพิมพ์
$display_name = preg_replace("/(" . $q . ")/i", "<b>$1</b>", $name);
echo "<li onselect=\"this.setText('$name').setValue('$id');\">".$display_name."</li>";
}
mysql_close();
?>



gdata.php






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-08-22 15:18:42 By : nornatt
 


 

No. 2



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



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


เห็นโค้ดแล้วต้องใช้เวลาครับ สงสัยว่าสคริปท์นี้เคยรันได้มั๊ย..
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-08-22 15:54:42 By : cowboycnx
 

 

No. 3



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



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


ตอบความคิดเห็นที่ : 2 เขียนโดย : cowboycnx เมื่อวันที่ 2014-08-22 15:54:42
รายละเอียดของการตอบ ::
เคยรันได้คะ แต่มันแบบ ผสมกันเยอะไปนิดนึง หนูก็อยากจะแยกหน้านะคะ แต่แบบ ส่งค่าไม่ค่อยจะเป็น

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-08-23 10:06:36 By : nornatt
 


 

No. 4



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



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


ลองตัดออกทีละตัวดูก่อนครับ ค่อยๆย้อนกลับไปทีละขั้นจนกว่า มันจะเริ่มกลับมาทำงานได้ปกติ

แล้วหลังจากนั้น ค่อยๆเพิ่มโค้ดเข้าไปทีละส่วน ถ้าเพิ่มแล้วติด รันไม่ได้ แสดงว่าโค้ดที่เพิ่มเข้าไปล่าสุด

อาจไปทับซ้อนกับส่วนที่มีอยู่ก่อนหน้านี้


ถ้าจะให้ช่วยแก้โค้ดชุดนี้ ผมเกรงว่าจะทำไม่ได้ เพราะสภาพแวดล้อมในเครื่องของผม ต่างจากเครื่องของน้อง nornatt
ได้แต่แก้แบบเดาๆอาการ จะให้นั่งทำความเข้าทุกเสตทเมนท์ก็คงไม่มีเวลา จะให้ง่ายที่สุดก็คือการรีโมทเข้าไปแก้ให้โดย
ใช้ team viewer สะดวกที่สุดครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-08-23 11:23:04 By : cowboycnx
 


 

No. 5



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



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





ประวัติการแก้ไข
2014-08-23 16:21:52
2014-08-23 16:57:58
2014-08-23 16:58:02
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-08-23 15:46:11 By : nornatt
 

   

ค้นหาข้อมูล


   
 

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