inspiration_ryan
inspiration_ryan

Reputation: 37

Pre populate select based on submitted value from the same select

I have a select box which when selected reloads the page, how can I make sure the select still holds the selected value after the page reloads?

Thanks

Upvotes: 1

Views: 173

Answers (2)

Kumar Rakesh
Kumar Rakesh

Reputation: 2708

Actually thier is no way for catch the selected value after reloads the page. You can do it :

  1. By Post
  2. By Get
  3. By Session
  4. By cookie
  5. Or BY ajax (Not reload the page)

You can selected option by this way value test . e.g.

if(isset($_POST['select']) && $_POST['select']==2){ echo "<option value='2' selected>Second</option>"; }  

Same thing you can do with other PHP GLobal variables.

Upvotes: 0

Cagy79
Cagy79

Reputation: 1620

Here already 2 options, there are probably many more:

  1. Do not reload the entire page but only populate the dynamic elements that change using ajax (asynchronous calls).
  2. Catch the selected value in PHP and set the selected <option selected> in the select list programatically

Succes!

Upvotes: 1

Related Questions