View previous topic :: View next topic |
Author |
Message |
Techek Smarty n00b
Joined: 24 Sep 2003 Posts: 1
|
Posted: Wed Sep 24, 2003 9:01 pm Post subject: selected="selected" does NOT work in Mozilla? |
|
|
I've been coding, checking, verifying, checking, crying and (almost) screaming of the result from HTML_OPTIONS. It seems that the result is displayed equally in Mozilla and (urgh) Internet Explorer, but it doesn't work the same way!?!?
This HTML shows "Joe" as selected in IE whereas "Fred" is displayed as selected in Mozilla?
Code: |
<select name=user>
<option label="bob" value="1">bob</option>
<option label="jim" value="2">jim</option>
<option label="joe" value="3" selected="selected">joe</option>
<option label="jerry" value="4">jerry</option>
<option label="fred" value="5">fred</option>
</select>
|
When will this error be corrected - or am I doing something wrong when doing it like this :
index.php
Code: |
$smarty->assign('id', array(1,2,3,4,5));
$smarty->assign('name', array('bob','jim','joe','jerry','fred'));
$smarty->assign('user', 3);
|
index.tpl
Code: |
<select name=user>
{html_options values=$id output=$name selected=$user}
</select>
|
|
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Sep 24, 2003 9:14 pm Post subject: Re: selected="selected" does NOT work in Mozilla? |
|
|
Techek wrote: | This HTML shows "Joe" as selected in IE whereas "Fred" is displayed as selected in Mozilla? |
if so, it's a bug in mozilla. |
|
Back to top |
|
andre Smarty Pro
Joined: 23 Apr 2003 Posts: 164 Location: Karlsruhe, Germany
|
Posted: Thu Sep 25, 2003 6:19 am Post subject: |
|
|
I have noticed the same strange behaviour using Firebird. It's definitely a bug in Mozilla engine. |
|
Back to top |
|
scdgro Smarty Regular
Joined: 24 May 2003 Posts: 39 Location: Netherlands
|
Posted: Tue Sep 30, 2003 5:51 pm Post subject: |
|
|
I only use the word selected, and it works fine with mozilla
I haven't seen this behavior yet, but that's because i haven't tested it yet. |
|
Back to top |
|
joelgriffiths Smarty n00b
Joined: 29 Aug 2004 Posts: 3 Location: Phoenix, AZ
|
Posted: Sat Sep 25, 2004 2:32 am Post subject: selected="selected" is not a bug but should be fix |
|
|
While the w3c states that boolean values can be expressed either alone or with an assignment, it also points out that many user agents don't recognize the non-minimized form. For that reason, it would be best if Smarty conformed to the minimized form.
For those fighting with this issue, change line 102 of /usr/local/lib/php/Smarty/[libs/]plugins/function.html_options.php.
Versions 2.6.3 - 2.6.5
From the w3c......
http://www.w3.org/TR/html401/intro/sgmltut.html#h-3.3.4.2
Boolean attributes
Some attributes play the role of boolean variables (e.g., the selected attribute for the OPTION element). Their appearance in the start tag of an element implies that the value of the attribute is "true". Their absence implies a value of "false".
Boolean attributes may legally take a single value: the name of the attribute itself (e.g., selected="selected").
This example defines the selected attribute to be a boolean attribute.
selected (selected) #IMPLIED -- option is pre-selected --
The attribute is set to "true" by appearing in the element's start tag:
<OPTION selected="selected">
...contents...
</OPTION>
In HTML, boolean attributes may appear in minimized form -- the attribute's value appears alone in the element's start tag. Thus, selected may be set by writing:
<OPTION selected>
instead of:
<OPTION selected="selected">
Authors should be aware that many user agents only recognize the minimized form of boolean attributes and not the full form. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Sat Sep 25, 2004 9:49 am Post subject: |
|
|
i prefer xhtml-compliant output. |
|
Back to top |
|
maw Smarty Rookie
Joined: 18 Apr 2003 Posts: 8 Location: Wellington, New Zealand
|
Posted: Wed Oct 06, 2004 9:01 am Post subject: Cached? |
|
|
selected="selected" works in Firefox - the same code base as Mozilla suite, but I got caught trying to "fix" this when the problem was that returning to the same page Firefox was choosing the PREVIOUS value rather than the SELECTED value until I used the 'Reset' button on the form. This may be a bug in Firefox, but it affects those of us developing forms more than those using the forms. |
|
Back to top |
|
norbee_usr Smarty n00b
Joined: 14 Oct 2004 Posts: 3
|
Posted: Thu Oct 14, 2004 9:26 am Post subject: |
|
|
i've also discovered this bug.
but as i experienced not even mozilla but IE also inproperly recognized the <OPTION ... selected="selected"> tag.
so i serched the line where smarty writes this out and changed it to <OPTION ... selected>.
now it seems ok
so i agree with joelgriffiths... "Authors should be aware that many user agents only recognize the minimized form of boolean attributes and not the full form."
|
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Oct 14, 2004 1:31 pm Post subject: |
|
|
I've noticed this problem during developement, and it only seems to apply when I am clicking "reload" to redraw a form. example, pull up the form in mozilla with value 3 selected. Then change the selected value to 5 in the code and hit "reload". Mozilla will still display value 3 as selected. If you put your cursor in the URL and press enter (or leave the form and come back to it from elsewhere), only then will it get the correct selected value. This isn't something normally encountered outside of development (selected vals changing between reloads), so not a crucial bug but still a bug. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Oct 14, 2004 1:40 pm Post subject: |
|
|
example to demonstrate the problem, create this static html file:
Code: | <form>
<select name="foo">
<option value="1">1</option>
<option value="2" selected="selected">2</option>
<option value="3">3</option>
</select>
</form> |
display in your browser, value "2" is selected.
Now change the selected value to "3" in the code and hit reload. Mozilla will continue to display value "2" as selected. You must hold down shift-reload to get the selected value correct, or put your cursor in the URL and press enter. You can even change text on the page and mozilla will pick up the changes but still show the wrong selected value! |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Oct 14, 2004 1:44 pm Post subject: |
|
|
It also doesn't seem to matter if you use selected or selected="selected" |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Oct 14, 2004 1:57 pm Post subject: |
|
|
Looking at the mozilla bug database, this is in there (and duplicated a few times). What it boils down to: this is not a bug Mozilla attempts to keep the currently selected form values on a page reload (do not "reset" them to the defaults). Therefore if you change which value was selected by default, tough luck.... mozilla still retains the currently selected value unless you shift-reload or press enter in the URL. |
|
Back to top |
|
norbee_usr Smarty n00b
Joined: 14 Oct 2004 Posts: 3
|
Posted: Thu Oct 14, 2004 8:16 pm Post subject: |
|
|
hm...
but it still works for me (in both browsers) if i use selected insetead of selected="selected"
(browser versions: IE6, mozilla1.7.3)
again:
as i see replacing selected="selected" -> selected in function.html_options.php (in line 102) solved this problem.
so... what now? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Oct 14, 2004 8:28 pm Post subject: |
|
|
Exactly when does the problem happen? Only when reloading the browser after the selected item changes? If so, this shouldn't be showstopper, this doesn't happen in a production application. (?) |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Oct 14, 2004 9:45 pm Post subject: |
|
|
what DOCTYPE do you give on the page where selected="selected" doesn't work? |
|
Back to top |
|
|