Page 1 of 1

default selected option in select box

Posted: Wed Aug 07, 2002 5:17 am
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?

Posted: Wed Aug 07, 2002 6:18 am
by Craig
<OPTION VALUE="66" selected>bon1</OPTION> ?

Posted: Wed Aug 07, 2002 7:08 am
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"";

Posted: Wed Aug 07, 2002 8:31 am
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>