drop down boxes and database html/php help required

hi, im fetching options for a drop down box from a database which is all working appropriately. i have implemented an admin section where you can update each player's information in the database for a football website. my question is when the update for a member is selected i want the drop down box to select the value that is already stored from the database.

for example a member can have a player position i.e. gk/def/mf/amf/str

i want the option that has previosly been chosen and stored in the database to be selected as default when the update profile of that player is loaded. currently it defaults to the first value and if you dont change again each time, you end up i.e. with gk for a striker. its easy to alter just annoying if you forget and would be much better if this is implemented. i also need it for other things like match reports, i.e. venue - home/away/neutral.


and one additional question, how do you make a drop down box auto goto a page when the value is selected opposed to having a button that directs to the page, this is also from fetching the values from a database.

thanks in advance
kostonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Cem TürkSenior Software EngineerCommented:
just read the position data from the db to a var and write it as the first option in the combobox

<form name="form1" method="post" action="blabla.php">
<select name="position" >
<option value="gk">Goalkeeper</option>
<option value="def">Defender</option>
<option value="mid">Goalkeeper</option>
</select>
</form>
<?php if(isset($pos)) { echo '<script type="text/javascript">document.form1.position.value="' . $pos . '"</script>'; } ?>

the above code sets the selected value via javascript

the following code will submit its form when a value from combobox is slected

<form name="test" action="blabla.php" method="post">
<select name="position" onchange="this.form.submit();">
<option value="gk">Goalkeeper</option>
<option value="def">Defender</option>
<option value="mid">Goalkeeper</option>
</select>
</form>

i can be more specific if you post your code

Cem

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kostonAuthor Commented:
hey mate that works fine thanks, you don't by any chance know the answer to the 2nd question i asked do you?
Cem TürkSenior Software EngineerCommented:
>and one additional question, how do you make a drop down box auto goto a page when the value is selected >opposed to having a button that directs to the page, this is also from fetching the values from a database.

you mean this ?

<select name="navigate" onchange="document.href.location=this.value;">
<option value="www.google.com">Google</option>
<option value="www.experts-exchange.com">Experts Exchange</option>
</select>
kostonAuthor Commented:
cant seem to get it to work mate, keeps saying errors on this page


this is the drop down box+ button i want to change to auto:

<form name="show1" action="<? echo "matches.php?show=".$show; ?>" method="get" >
  <select name="show" class="textArea" >
  <option value="all">All</option>
  <option value="league">league</option>
  <option value="cup">cup</option>
  <option value="friendly">friendly</option>
  <option value="other">other</option>
  </select>
  <input type="SUBMIT"  value="show" class="formButton">
                                     
              <?php
              $var = $_GET['show'];
              if(isset($var)) { echo '<script type="text/javascript">document.show1.show.value="' . $var . '"</script>'; } ?>
</form>
Cem TürkSenior Software EngineerCommented:
<form name="show1" action="<? echo "matches.php?show=".$show; ?>" method="get" onchange="this.form.submit();">
  <select name="show" class="textArea" >
  <option value="all">All</option>
  <option value="league">league</option>
  <option value="cup">cup</option>
  <option value="friendly">friendly</option>
  <option value="other">other</option>
  </select>
  <input type="SUBMIT"  value="show" class="formButton">
                               
            <?php
            $var = $_GET['show'];
            if(isset($var)) { echo '<script type="text/javascript">document.show1.show.value="' . $var . '"</script>'; } ?>
</form>
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.