default selected option in select box

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
darkshine
Forum Newbie
Posts: 15
Joined: Wed Aug 07, 2002 4:15 am
Location: paris, france

default selected option in select box

Post by darkshine »

Hi; the idea is to have a selected default option in a select box
using mysql database...

Code: Select all

//the file containing my form 
<FORM  METHOD="POST" ACTION="includes/update.inc" name="form_update">

<SELECT NAME="new_id_agence">
	<OPTION VALUE="66">bon1</OPTION>
	<OPTION VALUE="67">bon2</OPTION>
	<OPTION VALUE="68">bon3</OPTION>
</SELECT>

//and the update.inc file
//Contains the fields i get back from mysql
//
$result=@mysql_query($infos_user) or die ("error sql");
if ($infos= mysql_fetch_array($result))
	&#123;
	 $id_agence=htmlentities(stripslashes($infos&#1111;"id_agence"]));
	 $ip=htmlentities(stripslashes($infos&#1111;"ip"]));
	&#125;

OK?
The goal is to have the default value selected first, then update the list...

any idea?
Craig
Forum Commoner
Posts: 37
Joined: Thu Apr 18, 2002 3:13 pm

Post by Craig »

<OPTION VALUE="66" selected>bon1</OPTION> ?
darkshine
Forum Newbie
Posts: 15
Joined: Wed Aug 07, 2002 4:15 am
Location: paris, france

Post by darkshine »

that s not what i m asking for ...

In fact i want the option 'selected' depending on the value corresponding in my table
<option value="sthing" "/selected/">

(isset("$selected")?echo"$selected":echo"";
darkshine
Forum Newbie
Posts: 15
Joined: Wed Aug 07, 2002 4:15 am
Location: paris, france

Post by darkshine »

Well , i ve found the simple solution in javascript....
sometimes it s useful ....:)

<SCRIPT>
//affiche option par défaut le formulaire
form_update.new_id_agence.value='<?=$id_agence?>';
</SCRIPT>
Post Reply