dsa99349 2014-12-22 20:36
浏览 37
已采纳

在提交后以html形式保留第一个字段,然后在有人完成第一个字段后有一个主提交按钮

I am currently using this php form to submit into our mySQL database with a "chip_number" and "order_number" also with a date and time stamp. We want to use this with no keyboard or mouse, just a scanner. Currently it tabs the first field and when the second field is scanned the form is submitted, which is working as intended but it completely starts the form over, i would like it to keep the first field (order_number) after submitting so we can scan multiple "chip_numbers" on the same "order_number" then have a Master submit button if you will to send it all through when the employee is done with that order number and start with a blank form. This is the script i am using. thanks to all in advance!

   <!-- Insert -->
<?php
$servername = "servername";
$username = "username";
$password = "password";
$dbname = "dbname";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "INSERT INTO MICROCHIP_TBL (chip_number,order_number)
VALUES 
('$_POST[chip_number]','$_POST[order_number]')";

IF (mysqli_query($conn, $sql)) {
    echo "New record created successfully";
} else {
    echo "Error: TRY AGAIN HUMAN!";
}

mysqli_close($conn);
?>

<html>
<head>
<!-- Validate form function -->
<!--<script type="text/javascript">
//  function validateForm()
//  {
//    var x=document.forms["chip_insert"]["order_number"].value;
//    var y=document.forms["chip_insert"]["chip_number"].value;
//    if (x==null || x=="")
//    {
//      alert("Please enter an Order Number.");
//      document.forms["chip_insert"]["order_number"].focus();
//      return false;
//    }
//    if (y==null || y=="")
//    {
//      alert("Please enter a Microchip Number.");
//      document.forms["chip_insert"]["chip_number"].focus();
//      return false;
//    }
//  }

</script> 
-->

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type="text/javascript">
  function getNextElement(field) {
    var form = field.form;
    for ( var e = 0; e < form.elements.length; e++) {
        if (field == form.elements[e]) {
            break;
        }
    }
    return form.elements[++e % form.elements.length];
}

function tabOnEnter(field, evt) {
if (evt.keyCode === 13) {
        if (evt.preventDefault) {
            evt.preventDefault();
        } else if (evt.stopPropagation) {
            evt.stopPropagation();
        } else {
            evt.returnValue = false;
        }
        getNextElement(field).focus();
        return false;
    } else {
        return true;
    }
}

</script>
</head>

<body onLoad="document.chip_insert.order_number.focus();">
<center>
<h1>Jeffers HomeAgain Microchip Entry</h1>


<form name="chip_insert"  id="chip_insert" action="<?php echo $PHP_SELF;?>" onsubmit="return validateForm()" method="post">
Order Number: <input tabindex="1" maxlength="11" type="text" name="order_number"  id="order_number"  required="required"onkeydown="return tabOnEnter(this,event)" /><br /><br />
Tag Number: <input tabindex="2" maxlength="15" type="text" name="chip_number" id="chip_number" required="required" /><br /><br />
<input tabindex="7" type="submit" />
</center>
</form>


  • 写回答

2条回答 默认 最新

  • dongpa2000 2014-12-22 22:01
    关注

    header('Location: http://JVSIntranet/microchip/homeagain.php');

    This code redirects back to the form, I guess. You should add the ordernumber so it can be picked up by the form.

    $ordernr = $_POST['order_number'];
    header("Location: http://JVSIntranet/microchip/homeagain.php?order_number=$ordernr"); //mark the double quotes
    

    in your form code you will have to use something like

      <?php  $value = (isset($_GET['order_number'])) ? " value=$_GET['order_number'] " : ""; ?>
        Order Number: <input tabindex="1" maxlength="11" type="text" name="order_number" id="order_number" <?php echo $value; ?> required="required"onkeydown="return tabOnEnter(this,event)" /><br /><br />
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 X轴为分离变量(因子变量),如何控制X轴每个分类变量的长度。
  • ¥30 求给定范围的全体素数p的(p-2)的连乘积
  • ¥15 VFP如何使用阿里TTS实现文字转语音?
  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计