简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM