使用PHP中的AJAX创建条形码阅读器

时间:2013-09-30 04:23:34

标签: php jquery html ajax barcode

我正在尝试使用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。这是我的代码,我很感谢帮助

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

1 个答案:

答案 0 :(得分:0)

您必须阻止“Enter”键的响应。如果您在项目中使用jquery,可以使用以下代码阻止它:

$(function() {

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

});

要将Enter键绑定到“部件号”字段,您可以尝试这样做:

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