Page 1 of 1

list box

Posted: Tue Aug 08, 2006 2:10 am
by shiranwas
hi,

this is my coding to add dynamically to a list box

Code: Select all

<?php

function loadDept(){
include('Conn.php');
$sql="Select deptName from tblDepartments order by deptName";
$query=mysql_query($sql) or die ("Deparments can not be loaded.");
	while($row=mysql_fetch_assoc($query)){
		$arrDeparments[]=$row;
	}
foreach ($arrDeparments as $d) echo "<OPTION>{$d['deptName']}</OPTION>\n";
}
?>

<select name="cboDept" ><? loadDept() ?> </select>

when i do this the list box show the first value always in the text area of the list box even without selecting a value how to get rid from this since, sometimes i do not want to save the value from this list box.

thanks

shiran

Posted: Tue Aug 08, 2006 2:23 am
by webproject
Hey shiran, you can always put a first "option" witch is empty =]

for example:

Code: Select all

<option value="">empty</option>
<option>value</option>
<option>value</option>
<option>value</option>
<option>value</option>
<option>value</option>

Posted: Tue Aug 08, 2006 2:40 am
by shiranwas
it works
thanks