html - Select field resets when page is reset -


i write code user can select option in select field. , have onchange="location = this.options[this.selectedindex].value;" on select tag , every option tag have own value.

so question this:

when select option select field, send query string same page , want selected option keep selected select field reset when page reset. it's wasn't such , work true, think make change in code (which can't find that) , make problem.

here code:

                    <?php                      parse_str($_server['query_string']);                      require ('../config.php');                      /* connect , select db codes*/                      $dbresult=mysqli_query($connection, "select * services");                      while($row = mysqli_fetch_array($dbresult)){                             $order_name = $row['name'];                             $order_id = $row['id'];                             echo "<option value=\"neworder.php?service=$order_id&quantity=1th\">$order_name</option>";                     }                     ?>                              </select><br/>     /* ...continue of codes...*/ 

you have specify option selected in attribute. option want select, need add selected="selected" attribute

in php done before echo statement, select option if order id same order id specified in query string

  if($service == $order_id){      $selected = "selected";   }   else{      $selected = "";   } 

and in echo statement

   echo "<option value=\"neworder.php?service=$order_id&quantity=1th\" ".$selected.">$order_name</option>"; 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -