sorry for my english.
I wonder if it’s possible to post with a submit button of the page A, a specific value to pre-select an item in a dropdown list of a form witch is in the page B.
I have that in the page A :
<form action="/form-test-pour-repo/" method="post">
<button type="submit" name="acces" value="choix 3">Choisir le 3</button>
</form>
and a form with a select in the page B
<select data-required_mark="required" data-field_type="select" data-original_id="liste">
<option value="">liste</option>
<option value="choix 1">je veux le 1</option>
<option value="choix 2">je veux le 2</option>
<option value="choix 3">je veux le 3</option>
</select>
But I didn’t succeed to pre-select "choix 3" when I arrive on the page B
Any help will be much appreciated
Caroline
3
Answers
You can use JS if you want. For example via sessionStorage or by setting a value on the server:
Without JS:
I will recommend you use a
get
method since the URL can be bookmarked or shared.Page A
Page B
Session storage
We can use the Web Storage API‘s
sessionStorage
to save the choice across pages.Page A can save the choice into
sessionStorage
:And page B can get it from
sessionStorage
to select the corresponding option:Query parameter
Data sent in a GET-request is part of the URL, as its query string. So by using the method GET instead of POST, then:
Simply change
method=post
in page A’s form tomethod=get
.Then on page B, retrieve the choice from the current URL and select the corresponding option:
Alternatively to selecting it in the front-end, you can select the option on the back-end as well. Selecting on the back-end comes with the benefits of caching and JS-independence.