ron kolel
ron kolel

Reputation: 49

get parameters from URL to html form

I created a button in html file that move to page with form:

<a class="btn goToProfile" href="{{ url_for('new_meeting', dog =  dog[0] ) }}">Click here to schedule a meeting</a>

I add the parameter dog to the GET request

http://127.0.0.1:5000/new_meeting?dog=123

When I move to the new page I have a form:

<form action="/favorites/add_meeting" method="post">
    <label for="time">Time:</label><br>
    <input type="datetime-local" id="time" name="time">
    <br>
    <br>
    <label for="place">Place:</label><br>
    <input type="text" id="place" name="place"><br>
    <br>
    <label for="place">Dog ID:</label><br>
    <input type="text" id="dog" name="dog" value="1" readonly><br><br>
    <br>
    <input type="submit" value="Submit">
</form>

How can I extract the parameter from the URL and add this to the value in the input tag?

Upvotes: 0

Views: 1584

Answers (1)

Mantas Daračiūnas
Mantas Daračiūnas

Reputation: 111

You can find here about how to get query parameters with JavaScript

When you have parameters let's say inside dogName variable. You can change form input field with id dog like this:

document.getElementById("dog").value = dogName

Upvotes: 1

Related Questions