php - I used loop to populate <select> options, how do make the select box show current option instead of the highest value? -


i have select box auto-populated options session variable. when select option , hit apply button, data relevant option displayed in text boxes on same page select (after short process page). part works fine.

they're sorted value, highest option "selected" one. if happen select option other top one, correct data show, select box still indicate highest value active.

sorry, don't explain things well, hope understand meant.

details: web based database management application, html/php/mysql/odbc

if got right, want maintain option after form submission depends on method use post or if post should use $_post , if should use $_get

you can use javascript deal it: 1 submit form when select option, no need button

in html:

  <select id="sortselect" class="sortselect" size="1" name="sort" onchange="this.form.submit();">              <option value="highestvalue" selected>highest value</option>             <option value="value1">value1</option>             <option value="value2">value2</option>         </select> 

in javascript tags:

<script type="text/javascript">     document.getelementbyid('sortselect').value = "<?php if(! $_get['sort']) echo $_session[1]; else  echo $_get['sort'];?>"; </script> 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -