A
A
Alexey Ochkasov2021-06-16 12:48:03
HTML
Alexey Ochkasov, 2021-06-16 12:48:03

How to transfer data from input to URL?

Hello. I need that when the button is clicked, the text goes from the input to the URL to the place of the asterisks. Please tell me how to do it. I use flask, so maybe somehow through a template engine? Preferably without JS and Python, everything is in HTML.

<form action="/searcha?title=***" method="GET">
    <label>
        <input type="text" name="search_content" placeholder="Поиск">
        <input type="submit" value="Найти">
    </label>
</form>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ochkasov, 2021-06-25
@DeD0k_CtaT1cT

Found a solution. I had to use JavaScript, but it was worth it.
HTML

<div class="search">
            <label>
                <input class="search_input" type="text" name="search_content" placeholder="Поиск">
                <input type="button" value="Найти" onclick="search_generate_url('title')">
            </label>
        </div>

JS
function search_generate_url(type) {
    let search_content = document.getElementsByClassName('search_input')[0].value
    let url = 'search?' + type + '=' + search_content;
    location.assign(url);
}

Instead , location.assign(url);you can use location.assign(location.href + url);if you need the parameters (in my case title) to be added, that is, /search?title=1, then /search?title=1search?title=1, etc. You can also use it
instead , it seems to be almost the same thing (it’s better to find out for sure, I didn’t understand), but I like the function more. location.assign(url)location.href = url;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question