Page 1 of 1
combo box's
Posted: Wed Sep 28, 2005 6:38 pm
by C_Calav
hi guys,
im gonna start a new post because it has strayed from my original problem. can i please have some help..
i have a select box with onChnage and when the page loads again i want that select to be 'selected' in the combo box.
i have some code there to do the 'selected' part but the output is comming up blank.
i cannot see what is wrong any help would be great!
Code: Select all
<form name="select_dept" action="/admin/users.php" method="post">
<select name="select_dept" onchange="this.form.submit();">
<option value="0" selected>Select Dept</option>
<option value="<?php echo $e_dept; ?>" <? echo (isset($_POST['select_dept']) && $_POST['select_dept'] == $row['select_dept'] ? ' selected="selected' : '');?>> <?php echo $e_dept; ?> </option>
<?php
include("conection.php");
$query = "select DISTINCT(e_dept) from tbl_emp";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
$e_dept = $row['e_dept'];
?>
<option value="<?php echo $e_dept; ?>"> <?php echo $e_dept; ?> </option>
<?php
}
?>
</select>
<input type="hidden" name="s_id" value="<?php echo "$s_id"; ?>">
</form>
Posted: Wed Sep 28, 2005 7:09 pm
by Jenk
The correct use of the option tags:
Code: Select all
<option value="blahdeblah" selected>blahdeblah</option>
<option value="yahdeyah">yahdeyah</option>

Posted: Wed Sep 28, 2005 7:58 pm
by C_Calav
Hi Jenk,
just looked at my code again, is it not in this format?
<option value="blahdeblah" selected>blahdeblah</option>
Jcart gave me the code to use, it doesnt look like its returning anything.
thanks
Posted: Wed Sep 28, 2005 8:32 pm
by Jenk
This part:
Code: Select all
<?php /*ignore this line*/ ?>
<option value="<?php echo $e_dept; ?>" <? echo (isset($_POST['select_dept']) && $_POST['select_dept'] == $row['select_dept'] ? ' selected="selected' : '');?>> <?php echo $e_dept; ?> </option>
That would output:
Code: Select all
<option value="e_dept_value" selected="selected> e_dept_value </option>
Change it to:
Code: Select all
<?php /*ignore this line*/ ?>
<option value="<?php echo $e_dept; ?>" <? if ($_POST['select_dept'] == $row['select_dept']) { echo ' selected'; } ?>> <?php echo $e_dept; ?> </option>

Posted: Wed Sep 28, 2005 8:57 pm
by Ambush Commander
Or add the ending quote to the selected.
Code: Select all
<?php /*ignore this line*/ ?>
<option value="<?php echo $e_dept; ?>" <? echo (isset($_POST['select_dept']) && $_POST['select_dept'] == $row['select_dept'] ? ' selected="selected"' : '');?>> <?php echo $e_dept; ?> </option>
Posted: Wed Sep 28, 2005 9:30 pm
by C_Calav
thanks guys for your help,
i did the changes and the combo box is displaying a blank option for "selcted"
is something else wrong? am i on the right track?
here is what i have now.
Thankyou
Code: Select all
<form name="select_dept" action="/admin/users.php" method="post">
<select name="select_dept" onchange="this.form.submit();">
<option value="<?php echo $e_dept; ?>" <? if ($_POST['select_dept'] == $row['select_dept']) { echo ' selected'; } ?>> <?php echo $e_dept; ?> </option>
<?php
include("conection.php");
$query = "select DISTINCT(e_dept) from tbl_emp";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
$e_dept = $row['e_dept'];
?>
<option value="<?php echo $e_dept; ?>"> <?php echo $e_dept; ?> </option>
<?php
}
?>
</select>
<input type="hidden" name="s_id" value="<?php echo "$s_id"; ?>">
</form>
Posted: Thu Sep 29, 2005 4:16 am
by Jenk
Ambush Commander wrote:Or add the ending quote to the selected.
Code: Select all
<?php /*ignore this line*/ ?>
<option value="<?php echo $e_dept; ?>" <? echo (isset($_POST['select_dept']) && $_POST['select_dept'] == $row['select_dept'] ? ' selected="selected"' : '');?>> <?php echo $e_dept; ?> </option>
That's also the other thing I was pointing out, it's not supposed to be
Code: Select all
<option value="123" selected="selected">123</option>
The correct use is
Code: Select all
<option value="123" selected>123</option>

Posted: Thu Sep 29, 2005 4:59 am
by mickd
both should work though selected="selected" should be better.
in xhtml
Attribute Minimization Is Forbidden
Here is a list of the minimized attributes in HTML and how they should be written in XHTML:
HTML
XHTML
compact
compact="compact"
checked
checked="checked"
declare
declare="declare"
readonly
readonly="readonly"
disabled
disabled="disabled"
selected
selected="selected"
defer
defer="defer"
ismap
ismap="ismap"
nohref
nohref="nohref"
noshade
noshade="noshade"
nowrap
nowrap="nowrap"
multiple
multiple="multiple"
noresize
noresize="noresize"
http://www.w3schools.com/xhtml/xhtml_syntax.asp
Posted: Thu Sep 29, 2005 5:00 am
by Jenk
Hmm.. probably should have checked there first, but a different site which displayed XHTML standards had just selected.
Posted: Thu Sep 29, 2005 4:22 pm
by C_Calav
Hi guys,
thanks for your help.
is this still my problem? because i see all the quotes in the right places?
Ambush Commander wrote:
Or add the ending quote to the selected.
thanks
Posted: Fri Sep 30, 2005 3:34 am
by Jenk
Yes, add the trailing quote and it should be fine
