PDA

View Full Version : At below code if I want to use rather selected the selected="selected"



leonidassavvides
08-03-2008, 01:55 PM
At below code if I want to use rather selected the selected="selected"

<?php
/* $curdate = getdate();
$curday = $curdate['mday'];
$curmonth = $curdate['mon'];
$curyear = $curdate['year']; */
for ($i = 2008; $i <= 2010; $i++)
{
if ($i == $curyear)
echo '<option value="', $i, '" selected>', $i, '</option>';
else
echo '<option value="', $i, '">', $i, '</option>';
}
?>


this is correct below ?


echo '<option value="', $i, '" selected=', '"selected', '">', $i, '</option>';

allahverdi
08-03-2008, 05:49 PM
echo '<option value = " '.$i.' " selected = "selected">'.$i.'</option>';

Try this one. I think it will work

techietim
08-03-2008, 05:51 PM
This should work:


<?php
/* $curdate = getdate();
$curday = $curdate['mday'];
$curmonth = $curdate['mon'];
$curyear = $curdate['year']; */
for ($i = 2008; $i <= 2010; $i++)
{
echo ($i == $curyear) ? '<option value="' . $i . '" selected="selected">' . $i . '</option>':'<option value="' . $i . '">' . $i . '</option>';
}
?>

sm1le
08-04-2008, 09:19 PM
you don't have to use selected="selected", just write <option value="'.$i.'" SELECTED> and it works!
This is how I like to do it:


<?php
/* $curdate = getdate();
$curday = $curdate['mday'];
$curmonth = $curdate['mon'];
$curyear = $curdate['year']; */
for ($i = 2008; $i <= 2010; $i++)
{
echo '<option value="'.$i.'" '; if($i == $curyear){echo 'SELECTED';} echo '>', $i, '</option>';
}
?>

allahverdi
08-05-2008, 04:54 AM
Sm1le, look at thread name...

leonidassavvides
08-05-2008, 12:41 PM
I am using XHTML TRANS. 1.0 and not validate by that, i need to be valid ...

techietim
08-05-2008, 01:29 PM
Using my example should make it proper.