jeudi 20 août 2020

Set input value to get variable

I have two web pages.

index.php

This contains a form

<form id="searchForm" class="" action="search.php" method="get" style="position:absolute; top:150pt; left:10pt; font-size:17pt;">
  <label for="">Postcode</label>
  <input type="text" id="postcode" name="postcode" value="" placeholder="AB12 3CD" oninput="checkPostcode()">
  <!-- function isValidPostcode(p) {
        var postcodeRegEx = /[A-Z]{1,2}[0-9]{1,2} ?[0-9][A-Z]{2}/i;
        return postcodeRegEx.test(p);
    } -->
  <br>
  <label for="">Type of Course</label>
  <select class="" name="coursetype">
    <option value="" disabled selected></option>
    <option value="online">Online</option>
    <option value="">In Person</option>
  </select>
  <br>

  <input type="submit" value="Search">
</form>

when the form has submitted the action in search.php

search.php

This shows the same form with the inputted data from the previous page

<?PHP $postcode = $_GET['postcode'];?>
    <form class="" action="search.php" method="get">
    Postcode <input type="text" name="postcode" value="
    <?php
    $postcode = str_replace('%20', ' ', $postcode);
    $postcode = str_replace('-', ' ', $postcode);
    $postcode = str_replace('%09', '', $postcode); // This line was added to try to remove 
    the tabs
    echo $postcode;
    ?>
    ">

    Tags


    <select id="tagsInput" class="js-example-basic-hide-search-multi" name="specialities[]" 
    multiple="multiple" onkeyup="filterTags()">
        <option value="AL">Lorem</option>
        <option value="WY">ipsum</option>
    </select>

    <script>
    $(document).ready(function() {
        $('.js-example-basic-hide-search-multi').select2({language: "en"});
    })
    </script>
    <script>
    function filterTags() {
        var input, filter, table, tr, td, i, txtValue;
        input = document.getElementById("tagsInput");
        filter = input.value.toUpperCase();
        table = document.getElementById("searchTable");
        tr = table.getElementsByTagName("tr");
        for (i = 0; i < tr.length; i++) {
            td = tr[i].getElementsByTagName("td")[2];
            if (td) {
                txtValue = td.textContent || td.innerText;
                if (txtValue.toUpperCase().indexOf(filter) > -1) {
                    tr[i].style.display = "";
                } else {
                    tr[i].style.display = "none";
                }
            }
        }
    }
    </script>
    <input type="submit" value="Submit">
</form>

However, when the input is shown in search.php, there are two tabs on either side of the input.

How do I get rid of this?

View screenshot of result here




Aucun commentaire:

Enregistrer un commentaire