0

Have been working on a smaller project with php here and got lost. I'll explain in two parts.

Part 1: I have index.php and a getitem.php. Index contains a form with multiple select objects with no options (at start) with the exception of one. After selecting an item from the one with options available I make a query via getitem.php&[parameters_here]. The php then echoes options with values and texts.

This form then guides you to fill every field this way. These options are added on the go with object.innerhtml. Everything fine.

The problem kicks in when you hit the refresh button. Select items lose their options (with the exception of the one). How to keep these settings on refresh? Keeping them in a _SESSION? Checking the session for every single select item seems too brute force.

Part 2: Would fixing this help me out with a library like this; to see the dynamic options with images? I believe these two parts are connected.

Thanks.

Community
  • 1
  • 1
Dave8813
  • 21
  • 4
  • Possible duplicate of [keep option selected after a refresh](http://stackoverflow.com/questions/22192640/keep-option-selected-after-a-refresh) –  Mar 31 '16 at 10:15
  • Already checked that one. Note that I have an empty select object on refresh. Storing the whole options list is a possible way, sure, but surely there is a better solution. – Dave8813 Mar 31 '16 at 10:29

1 Answers1

0

About Part 1:

The key point is refreshing the page. First let us consider the case what is happening now - you are probably keeping the options selected using $_POST. After the selection and reloading is done it shows the response of POST action [as your data is being posted into the same page - guessing from your scenario]. Now when somebody reloads the browser the POST request becomes empty. So all the selections are lost.

There can be lots of ways/tricks for this. $_SESSION can be one of them / $_COOKIE can be one of them / through some JS you can use browser local storage, etc.

The main concept will be the fact to keep the values somewhere where a browser refresh doesn't effect. So though $_SESSION seems brut force to you -- it is a logical option.

About Part 2:

I think these two parts are not connected. As long as you are using regular select options for showing your options - they are not connected -- as your part two deals with styling your option values not how the work.

Himel Nag Rana
  • 744
  • 1
  • 11
  • 19