Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get params from <input> and redirect to another link with data

Basically I Developed microservice on SpringBoot, that takes data from excel form and shows it as a table. I figured out how to do this, it works fine.

Now I used Elastic search that works fine when I send the request by my self. Now I need this to work on thymeleaf html.

Basically my page looks like this now

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

My html ss

What I need is, I input my search into search bar, and when I press the "Submit" button, it takes the searchRequest from search bar, redirects to the other link with the parameters the user entered before. Here is my html code

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Freight Masters LLC Agents</title>

    <style>
        /*** COLORS ***/
        /*** DEMO ***/
        html,
        body {
            height: 100%;
            margin: 0;
        }
        body {
            background: #F4B942;
            font: 13px monospace;
            color: #232e57;
        }
        p {
            margin-top: 30px;
        }
        .cntr {
            display: table;
            width: 100%;
            height: 100%;
        }
        .cntr .cntr-innr {
            display: table-cell;
            text-align: center;
            vertical-align: middle;
        }
        /*** STYLES ***/
        .search {
            display: inline-block;
            position: relative;
            height: 35px;
            width: 35px;
            box-sizing: border-box;
            margin: 0px 8px 7px 0px;
            padding: 7px 9px 0px 9px;
            border: 3px solid #232e57;
            border-radius: 25px;
            transition: all 300ms ease;
            cursor: text;
        }
        .search:after {
            content: "";
            position: absolute;
            width: 3px;
            height: 20px;
            right: -5px;
            top: 21px;
            background: #232e57;
            border-radius: 3px;
            transform: rotate(-45deg);
            transition: all 300ms ease;
        }
        .search.active,
        .search:hover {
            width: 300px;
            margin-right: 0px;
        }
        .search.active:after,
        .search:hover:after {
            height: 0px;
        }
        .search input {
            width: 100%;
            border: none;
            box-sizing: border-box;
            font-family: Helvetica;
            font-size: 15px;
            color: inherit;
            background: transparent;
            outline-width: 0px;
        }

        .button {
            width: 180px;
            height: 45px;
            font-family: 'Roboto', sans-serif;
            font-size: 11px;
            text-transform: uppercase;
            letter-spacing: 2.5px;
            font-weight: 500;
            color: #000;
            background-color: #fff;
            border: none;
            border-radius: 45px;
            box-shadow: 0px 8px 15px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease 0s;
            cursor: pointer;
            outline: none;
        }

        .button:hover {
            background-color: #232e57;
            box-shadow: 0px 15px 20px #0f152b66;
            color: #fff;
            transform: translateY(-7px);
        }

    </style>
</head>
<body>
    <div class="cntr">
        <div class="cntr-innr">
            <label style="margin-bottom: 32px" class="search" for="inpt_search">
                <input th:name="searchParams" id="inpt_search" type="text"/>
            </label><br>
            <button class="button">Submit</button>
        </div>
    </div>
    <script src="https://code.jquery.com/jquery-3.6.1.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>
    <script>
        $("#inpt_search").on('focus', function () {
            $(this).parent('label').addClass('active');
        });

        $("#inpt_search").on('blur', function () {
            if($(this).val().length == 0)
                $(this).parent('label').removeClass('active');
        });
    </script>
</body>
</html>

Thanks in Advance.

>Solution :

You could probably use something like the following.
As an aside, I would advice to wrap this into a <form> element.

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Freight Masters LLC Agents</title>

    <style>
        /*** COLORS ***/
        /*** DEMO ***/
        html,
        body {
            height: 100%;
            margin: 0;
        }
        body {
            background: #F4B942;
            font: 13px monospace;
            color: #232e57;
        }
        p {
            margin-top: 30px;
        }
        .cntr {
            display: table;
            width: 100%;
            height: 100%;
        }
        .cntr .cntr-innr {
            display: table-cell;
            text-align: center;
            vertical-align: middle;
        }
        /*** STYLES ***/
        .search {
            display: inline-block;
            position: relative;
            height: 35px;
            width: 35px;
            box-sizing: border-box;
            margin: 0px 8px 7px 0px;
            padding: 7px 9px 0px 9px;
            border: 3px solid #232e57;
            border-radius: 25px;
            transition: all 300ms ease;
            cursor: text;
        }
        .search:after {
            content: "";
            position: absolute;
            width: 3px;
            height: 20px;
            right: -5px;
            top: 21px;
            background: #232e57;
            border-radius: 3px;
            transform: rotate(-45deg);
            transition: all 300ms ease;
        }
        .search.active,
        .search:hover {
            width: 300px;
            margin-right: 0px;
        }
        .search.active:after,
        .search:hover:after {
            height: 0px;
        }
        .search input {
            width: 100%;
            border: none;
            box-sizing: border-box;
            font-family: Helvetica;
            font-size: 15px;
            color: inherit;
            background: transparent;
            outline-width: 0px;
        }

        .button {
            width: 180px;
            height: 45px;
            font-family: 'Roboto', sans-serif;
            font-size: 11px;
            text-transform: uppercase;
            letter-spacing: 2.5px;
            font-weight: 500;
            color: #000;
            background-color: #fff;
            border: none;
            border-radius: 45px;
            box-shadow: 0px 8px 15px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease 0s;
            cursor: pointer;
            outline: none;
        }

        .button:hover {
            background-color: #232e57;
            box-shadow: 0px 15px 20px #0f152b66;
            color: #fff;
            transform: translateY(-7px);
        }

    </style>
</head>
<body>
    <div class="cntr">
        <div class="cntr-innr">
            <label style="margin-bottom: 32px" class="search" for="inpt_search">
                <input th:name="searchParams" id="inpt_search" type="text"/>
            </label><br>
            <button class="button submit_search">Submit</button>
        </div>
    </div>
    <script src="https://code.jquery.com/jquery-3.6.1.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>
    <script>
        $("#inpt_search").on('focus', function () {
            $(this).parent('label').addClass('active');
        });

        $("#inpt_search").on('blur', function () {
            if($(this).val().length == 0)
                $(this).parent('label').removeClass('active');
        });
        
        /// On submit
        $(".submit_search").on('click', function () {
          var searchString = $("#inpt_search").val();
          /// Use searchString
          /// (example)
          window.open("https://www.example.com/?query="+ searchString);
        });
    </script>
</body>
</html>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading