2013-09-30 55 views
1

我正在嘗試使用php構建應用程序。在「stock_out.php」中,我想創建一個包含兩個條形碼的表單。我有8個領域。 (1)EFFECTIVEDATE,(2)部分號碼,(3)說明1,(4)說明2,(5)NPK,(6)那抹,(7)QtyOut,(8)的原因。我想在「Partnumber」和「NPK」中使用條碼閱讀器。
我遇到了一些問題:
1.當我按下回車鍵時,它對按鈕提交進行響應。
2.實際上,當我按PartNumber中的輸入時,我想要在「description1」和「description2」中顯示詳細信息數據。和NPK一樣,我想在「nama」中顯示詳細數據
3.在表格末尾,我仍然希望將此表單提交到數據庫中。
我是AJAX的新手,所以我仍然不知道如何在PHP中實現AJAX。這是我的代碼,我感謝您的幫助在PHP中使用AJAX創建條形碼閱讀器

<html><body> 
<div id="outerContainer"> 
    <?php include("headerFile.html"); ?> 
    <?php include("navigationFile.html"); ?> 
    <div id="bodyContainer"> 
     <div id="pageBodyTitle"> Stock Out </div> <br> 
     <form id="formSearch" name="formSearch" method="post" action="proses_out.php" onSubmit="return cek_data();"> 
     <table id="messageTable"> 
      <tr> 
       <td class="heading"> Effective Date </td> 
       <td> 
        <input class="inputField" name="tgl" type="text" readonly value="<?php echo $_POST['tgl']?>" tabindex="1"/> 
        <script language='JavaScript'>new tcal ({'formname': 'formSearch','controlname': 'tgl'});</script> 
       </td> 
      </tr> 
      <tr> 
       <td class="heading"> Part Number </td> 
       <td><input type='text' name='txtItem' id='txtItem' size="20" class="inputField" value='<?php echo $item;?>' tabindex="2" /> 
       <img src='search.ico' onClick='open_win_item()'> </td> 
      </tr> 
      <tr> 
       <td class="heading">Description1</td> 
       <td><input type='text' name='txtDesc1' id='txtDesc1' size="50" value='<?php echo $desc1;?>' readonly /></td> 
      </tr> 
      <tr> 
       <td class="heading">Description2</td> 
       <td><input type='text' name='txtDesc2' id='txtDesc2' size="50" value='<?php echo $desc2;?>' readonly /></td> 
      </tr> 
      <tr> 
       <td class="heading"> NPK </td> 
       <td><input type='text' name='txtNpk' id='txtNpk' size="20" maxlength="5" class="inputField" value='<?php echo $tr_no;?>' tabindex="3" /> 
        <img src='search.ico' onClick='open_win_npk()'></td> 
      </tr> 
      <tr> 
       <td class="heading">Nama</td> 
       <td><input type='text' name='txtName' id='txtName' size="30" value='<?php echo $nama;?>' readonly /></td> 
      </tr> 
      <tr> 
       <td class="heading"> Qty Out </td> 
       <td><input type='text' name='txtQty' id='txtQty' size="5" class="inputField" tabindex="4"/></td> 
      </tr> 
      <tr> 
       <td class="heading"> Reason </td>     
       <td><select class="inputField" name="choose" id="choose" value="" tabindex="5"> 
       <?php 
       include "/class/connect_SQL.class.php"; 
       $sql = "select reason_code from Inv_reason_master"; 
       $query = mssql_query($sql); 
        while ($row = mssql_fetch_array($query)) 
        { 
         $coba = $row['reason_code']; 
        ?> 
         <option value="<?php echo $coba; ?>"><?php echo $coba;?></option> 
        <?php 
        } 
        ?> 
       </select></td> 
      </tr> 
      <tr> 
       <td colspan="2"> 
        <input type="submit" name="Submit" value="Save" class="formButton2" tabindex="6"/> 
        <input type="reset" name="reset" value="Cancel" class="formButton2" tabindex="7"/> 
       </td> 
      </tr> 
     </table> 

     </form> 
    </div> 
    <?php 
     if(isset($_GET["message"]) and $_GET["message"]='save') 
     { 
      echo "<script language=\"javascript\"> alert('Data Tersimpan!') </script>"; 
     } 
    ?> 
    <?php include("footerFile.html"); ?> 
</div> 

+0

看到這個鏈接瞭解ajax在PHP http://www.bennadel.com/resources/presentations/jquery/demo21/ –

+0

可能的重複http://stackoverflow.com/questions/5004233/capture-all-of-the-forms-data-and -submit-it-to-php-script-jquery-ajax-post –

+0

它不重複,這只是提交表單... 我可以提交所有字段到數據庫,但我不能在條碼閱讀呃。 – Dila

回答

0

您必須防止「Enter」鍵 - 鍵的響應。如果你在你的項目中使用jQuery就可以防止其與此代碼:

$(function() { 

    $("form").bind("keypress", function(e) { 
      if (e.keyCode == 13) return false; 
     }); 

}); 

要綁定回車鍵「零件號」字段,而不是你可以試試這個:

$('#txtItem').keypress(function(e) { 
    if (e.keyCode == 13) { 
     alert('Enter is pressed in part number'); 
    } 
});