0

Is it possible to set the selected option of a form via a previous selected option in an other form?

The select option is like this, here 60x60 is selected.

<select id="pa_afmetingen-vierkant" name="attribute_pa_afmetingen-vierkant">
  <option value="">Kies een optie…</option>
  <option value="m001">40x40</option>
  <option value="m002">50x50</option>
  <option selected="selected" value="m003">60x60</option>
  <option value="m004">70x70</option>
  <option value="m005">80x80</option>
  <option value="m006">100x100</option>
  <option value="m007">125x125</option>
  <option value="m008">150X150</option>
</select>

This form gets send to a new page, on this new page there is an exact duplicate of this form, I want this duplicate form to have the same option selected as was selected in the previous page.

My best bet would be to store the option in a variable , and via javascript select the option that matches the stored variable.

The form is submitted via POST

I don't really know what variable to use, nor how to target the option. Solutions requiring Jquery are not a problem.

Kind regards,

aynber
  • 22,380
  • 8
  • 50
  • 63
user25312
  • 187
  • 2
  • 16

1 Answers1

0

There are a few ways of implementing it.

One solution could be that you get the selected option in JS and pass it to the url like http://www.myurl.com?selectedOption=3. Then at the other page you could get that selected and trigger a select to your menu to select that value.

Get Selected Option's value

var selectedOption = $('#pa_afmetingen-vierkant option:selected').attr('value');

Retrieve Selected Option's value from URL

Refere Here

Set Selected Option in the NEW select menu

$('#pa_afmetingen-vierkant-NEW option[value='+ selectedOption +']').prop('selected', true);

Another solution could be that you store temporary the selectedOption in the localStorage and then you delete it from there.

Community
  • 1
  • 1
Thanassis_K
  • 272
  • 1
  • 9