根据输入自动填写表格?

时间:2017-06-06 09:24:36

标签: php html forms autofill

我有一张表格 并且在这种形式中有一个“klasse”,应该是一个重量范围,比方说975-1025。现在有20个权重要填写..有没有办法根据所述范围的范围自动填写这些数字输入? (975和1025)在输入上自动填充1000。
在此先感谢!!

<?php
     if(isset($_POST['update'])) {
        $dbhost = 'localhost';
        $dbuser = 'heijsdb_user';
        $dbpass = 'maus';

        $conn = ($GLOBALS["___mysqli_ston"] = mysqli_connect($dbhost,  $dbuser,  $dbpass));

        if(! $conn ) {
           die('Could not connect: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
        }
         $codering = 'RF-400.09';
         $revisie = '5';
         $controleur = $_POST['controleur'];



                        $sql = "INSERT INTO thermometer (Controleur, codering, revisie,)
                        VALUES ('$controleur', '$codering', '$revisie','$weeknr')"  ;
        mysqli_select_db($GLOBALS["___mysqli_ston"], heijsdb);

        $retval = mysqli_query( $conn ,  $sql);

        if(! $retval ) {
           die('Could not update data: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
        }
        echo "Formulier verstuurd.";

        ((is_null($___mysqli_res = mysqli_close($conn))) ? false : $___mysqli_res);
     }else {
        ?>
           <form method = "post" action = "<?php $_PHP_SELF ?>" id="form1">
        <table border ="2" cellspacing = "5" cellpadding = "5" align="center">
            <tr><td ><b>Controleur:</b></td><td colspan="4"><input type = "text" name="controleur" value="<?php echo $_SESSION["username"]; ?>" readonly></td></tr>
            <tr>
                <td>Product</td>
                <td><input type="text" name="product"></td>
            </tr>
            <tr>
                <td>Afnemer:</td>
                <td><input type="text" name="afnemer"></td>
            </tr>
            <td>Tijd:</td>
                <td><input type="time" name="tijd"></td>
            </tr>
            <tr>
                <td>Netto gew</td>
                <td><input type="number" name="netto"></td>
            </tr>
            <tr>
                <td>Gewicht klasse</td>
                <td><input type="number" name="klasse">
                <input type="number" name="klasse1">
                </td>
            </tr>
            <tr>
                <td>Kuiken 1</td>
                <td><input type="number" name="gew1"></td>
            </tr>
            <tr>
                <td>Kuiken 2</td>
                <td><input type="number" name="gew2"></td>
            </tr>
            <tr>
                <td>Kuiken 3</td>
                <td><input type="number" name="gew3"></td>
            </tr>
            <tr>
                <td>Kuiken 4</td>
                <td><input type="number" name="gew4"></td>
            </tr>
            <tr>
                <td>Kuiken 5</td>
                <td><input type="number" name="gew5"></td>
            </tr>
            <tr>
                <td>Kuiken 6</td>
                <td><input type="number" name="gew6"></td>
            </tr>
            <tr>
                <td>Kuiken 7</td>
                <td><input type="number" name="gew7"></td>
            </tr>
            <tr>
                <td>Kuiken 8</td>
                <td><input type="number" name="gew8"></td>
            </tr>
            <tr>
                <td>Kuiken 9</td>
                <td><input type="number" name="gew9"></td>
            </tr>
            <tr>
                <td>Kuiken 10</td>
                <td><input type="number" name="gew10"></td>
            </tr>
            <tr>
                <td>Kuiken 11</td>
                <td><input type="number" name="gew11"></td>
            </tr>
            <tr>
                <td>Kuiken 12</td>
                <td><input type="number" name="gew12"></td>
            </tr>
            <tr>
                <td>Kuiken 13</td>
                <td><input type="number" name="gew13"></td>
            </tr>
            <tr>
                <td>Kuiken 14</td>
                <td><input type="number" name="gew14"></td>
            </tr>
            <tr>
                <td>Kuiken 15</td>
                <td><input type="number" name="gew15"></td>
            </tr>
            <tr>
                <td>Kuiken 16</td>
                <td><input type="number" name="gew16"></td>
            </tr>
            <tr>
                <td>Kuiken 17</td>
                <td><input type="number" name="gew17"></td>
            </tr>
            <tr>
                <td>Kuiken 18</td>
                <td><input type="number" name="gew18"></td>
            </tr>
            <tr>
                <td>Kuiken 19</td>
                <td><input type="number" name="gew19"></td>
            </tr>
            <tr>
                <td>Kuiken 20</td>
                <td><input type="number" name="gew20"></td>
            </tr>





        <table class="w3-centered w3-panel">
            <tr>

            </tr>
          </tfoot>
        </table>

<style>td {
  padding: 15px;
  border: 1px solid #ddd;

    }
</style>
<input type="submit" name="update" value="Formulier versturen" class="w3-bar w3-red" action="<?php echo $_SERVER['PHP_SELF']; ?>">
   </form>

1 个答案:

答案 0 :(得分:1)

我不确定我明白你的意思:你是否想在用户写完第一个字段后自动填充所有20个字段? 如果是这样,您可以在输入更改时使用javascript:

document.getElementById('klasse1').value //you should add an id to that input

(请参阅此处以检测事件Detecting input change in jQuery?

然后您可以填充字段

document.getElementById('gew1').value = "the range";

您可以使用for循环遍历20个字段