maus
maus

Reputation: 51

Automatically fill in the form based on input?

I've got a form and in this form there is a "klasse", supposed to be a weight range lets say 975-1025. Now there are 20 weights to fill in.. is there a way to automatically fill in those number inputs based on the range of said range? (975 and 1025) auto fill 1000 on the inputs.
Thanks in advance!!

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

Upvotes: 1

Views: 121

Answers (1)

Marine Le Borgne
Marine Le Borgne

Reputation: 1056

I'm not sure I understand what you mean : do you want to autofill all of the 20 fields after a user has written in the first ? if so, you could use javascript on input change :

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

(see here for detecting the event Detecting input change in jQuery?)

Then you can populate the fields

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

you can use a for loop to loop through the 20 fields

Upvotes: 1

Related Questions