N
niyong
--
Hop@Ni
Hop@Ni
Grant Wagner said:from the <select> itself:
<select onchange="alert(this.options[this.selectedIndex].value);">
That will work in every browser I have.PatD said:I've been under the impression that this can be (savely)
shortened to:
<select onChange="alert(this[this.selectedIndex].value)">
Any browsers that wouldn't get this?
That will work in every browser I have.I've been under the impression that this can be (savely)
shortened to:
<select onChange="alert(this[this.selectedIndex].value)">
Any browsers that wouldn't get this?
Lee said:That will work in every browser I have.<select onChange="alert(this[this.selectedIndex].value)">
Now test "alert(options[selectedIndex].value)"
which is slightly shorter and probably slightly more standard.
Fails in NN4, though.Lee said:Mick White said:
PatD wrote:
I've been under the impression that this can be (savely)
shortened to:
<select onChange="alert(this[this.selectedIndex].value)">
Any browsers that wouldn't get this?
That will work in every browser I have.
Now test "alert(options[selectedIndex].value)"
which is slightly shorter and probably slightly more standard.
Fails in NN4, though.Mick White said:
PatD wrote:
I've been under the impression that this can be (savely)
shortened to:
<select onChange="alert(this[this.selectedIndex].value)">
Any browsers that wouldn't get this?
That will work in every browser I have.
Now test "alert(options[selectedIndex].value)"
which is slightly shorter and probably slightly more standard.
Lasse said:Lee said:Now test "alert(options[selectedIndex].value)"
<snip>I can't find a current browser where it makes a difference,
though.
PatD said:In a land long ago, in a time far away
Grant Wagner said:from the <select> itself:
<select onchange="alert(this.options[this.selectedIndex].value);">
I've been under the impression that this can be (savely)
shortened to:
<select onChange="alert(this[this.selectedIndex].value)">
Any browsers that wouldn't get this?
Yours
P
Grant said:this.options[this.selectedIndex].value
I wouldn't take the risk to save 8 characters. If I used the above codePatD said:<select onChange="alert(this[this.selectedIndex].value)"><select onchange="alert(this.options[this.selectedIndex].value);">
this.options[this.selectedIndex].value
document.forms['formName'].elements['elementName'] over
document.forms['formName']['elementName'] (or worse still:
PatD said:In a land long ago, in a time far away
[cut: almost everything]
[left: bare minimum to understand what's going on]
I wouldn't take the risk to save 8 characters. If I used the above codePatD said:<select onchange="alert(this.options[this.selectedIndex].value);">
<select onChange="alert(this[this.selectedIndex].value)">
this.options[this.selectedIndex].value
document.forms['formName'].elements['elementName'] over
document.forms['formName']['elementName'] (or worse still:
Interesting threat. Who would have thought so at its beginning?
Well, my personal favorite is:
this.options[this.selectedIndex].value
and, I'm slowly changing from
document.forms['formName']['elementName']
to
document.forms['formName'].elements['elementName']
Hm, I guess that some day, someone will start a threat on whether
"document.stuff..."
should not be replaced with
"window.document.stuff..."
Until then, see you, and thanks for all the feedback
Yours
P
Lasse said:Lee said:<select onChange="alert(this[this.selectedIndex].value)">
That will work in every browser I have.
Now test "alert(options[selectedIndex].value)"
which is slightly shorter and probably slightly more standard.
I'd say it was less standard, if anything. [...]
Richard said:Lasse said:Lee said:Now test "alert(options[selectedIndex].value)"
I can't find a current browser where it makes a difference,
though.
<snip>
It fails on Opera 6 (current on some phones apparently) and at least one
other embedded browser (NetFront?) that I have seen.
I think I would stick with:-
this.options[this.selectedIndex].value
- as it is HTML DOM standard [...]
Thomas said:Richard said:<snip>
It fails on Opera 6 (current on some phones apparently) and at least
one other embedded browser (NetFront?) that I have seen.
Those browsers should be considered borken or
at least not standards compliant in this regard.
Nonsense.
I think I would stick with:-
this.options[this.selectedIndex].value
- as it is HTML DOM standard [...]
Non sequitur. Following the scope chain specification is
not less standard. See ECMAScript 3 (2000), section 10.1.4.
Thomas said:Lasse said:Lee said:<select onChange="alert(this[this.selectedIndex].value)">
That will work in every browser I have.
Now test "alert(options[selectedIndex].value)"
which is slightly shorter and probably slightly more standard.
I'd say it was less standard, if anything. [...]
It should work in a standards compliant browser and it works in
Mozilla/5.0. "this" is part of the scope chain, so it does not
need to be mentioned explicitely.
Lasse said:Lee writes:
<select onChange="alert(this[this.selectedIndex].value)">
That will work in every browser I have.
Now test "alert(options[selectedIndex].value)"
which is slightly shorter and probably slightly more standard.
I'd say it was less standard, if anything. [...]
It should work in a standards compliant browser and it works in
Mozilla/5.0. "this" is part of the scope chain, so it does not
need to be mentioned explicitely.
You are falling into the trap of assuming that because Mozilla is the
most standard compliant browser then what Mozilla actually does is
standard. The custom scope chain that is built by Gecko browsers is
unique in terms of the object on the scope chain and the rules used to
construct it. Indeed, experimentation in this area suggests that none of
the browsers that provide custom scope chains for browser built
intrinsic event handling functions provides the same scope chain, or
uses the same rules for its construction, as any other. This is
behaviour that is not standardised.
Lee said:Some browsers may include additional objects in the scope chain,
but any that doesn't include "this" is pretty clearly broken.
Thomas 'PointedEars' Lahn said:Those browsers should be considered borken or
at least not standards compliant in this regard.
I think I would stick with:-
this.options[this.selectedIndex].value
- as it is HTML DOM standard [...]
Non sequitur. Following the scope chain specification is
not less standard. See ECMAScript 3 (2000), section 10.1.4.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.