another select question-- selected='selected' can't change?

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
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

another select question-- selected='selected' can't change?

Post by Skara »

Alright, this is screwy. I have three date dropdowns (day, month, year). Now when the page first loads, I have it put selected='selected' if the date is today.
e.g.

Code: Select all

<select name='day'>
<option>23</option>
<option selected='selected'>24</option>
<option>25</option>
</select>
The problem is, whenever I change it... it doesn't really change. It still uses the value from whatever the one is marked as 'selected.'

How can I have today active when the page loads, but read whatever the user enters?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

because you don't write selected='selected' you just write selected and that's it.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

whatever man . just telling you what i have working on my site. :-D if it messes up in the next browser release i'll look into it more:)
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post by pilau »

Maybe that is not supported by your browser.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

-_-' Firefox 1.0.7. I'm fairly certain it supports xhtml. *sighs*
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

http://en.wikipedia.org/wiki/XHTML#XHTML_1.0
Attribute minimization (e.g., <option selected>) is also prohibited; instead, use <option selected="selected">. More differences are detailed in the W3C XHTML specification [1].
which will lead you to
C.10. Boolean Attributes

Some HTML user agents are unable to interpret boolean attributes when these appear in their full (non-minimized) form, as required by XML 1.0. Note this problem doesn't affect user agents compliant with HTML 4. The following attributes are involved: compact, nowrap, ismap, declare, noshade, checked, disabled, readonly, multiple, selected, noresize, defer.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

$dropdown = '<select name="day">';
for ($x = 0; $x <= date('t',time()); $x++) {
   $dropdown .= '<option value="'.$x.'"';
   if (isset($_POST['day']) && $x == $_POST['day']) {
      $dropdown .= 'selected="selected"';
   }
   else if ($x == date('j',time()){
      $dropdown .= 'selected="selected"';
   }
   $dropdown .= '>';
}
$dropdown .= '</select>';
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

Eheh... uhm. Figured my problem out!

I'm uploading multiple files with bunches of data otherwise. I got myself confused on the many-dimentional arrays again. It kept trying to read the last one for all of them. ^^;

Thanks anyway... :oops:
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post by pilau »

Wikipedia wrote:C.10. Boolean Attributes

Some HTML user agents are unable to interpret boolean attributes when these appear in their full (non-minimized) form, as required by XML 1.0. Note this problem doesn't affect user agents compliant with HTML 4. The following attributes are involved: compact, nowrap, ismap, declare, noshade, checked, disabled, readonly, multiple, selected, noresize, defer.
See? Told you so.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

Hm. But nevertheless Firefox works fine on them. I've got giant multidimentional POST and FILES arrays and it all works spiffy now. ;)

I have IE, Opera, Konqueror, lynx, etc.. that I use to test my sites I do and it works just fine. I think this misinterpretation bug isn't a very large one. Even if it was once, most browsers would have tried to fix it now. *shrugs*
Post Reply