Thomas 'PointedEars' Lahn wrote:
[color=blue]
> Martin Honnen wrote:
>[/color]
[color=blue][color=green]
>> var input;
>> if (document.createElement) {
>> input = document.createElement('input');[/color]
>
>
> I *strongly* recommend to
>
> 1) declare variables only where needed[/color]
I see, that is why you have for instance
function createElement(sTagName)
{
var o = null;
if (sTagName
&& typeof document != "undefined"
&& dhtml.isMethodType(typeof document.createElement))
{
// remove
sTagName = sTagName.replace(/<?([^ >]+).*>?/, "$1");
o = document.createElement(sTagName);
in your lib, isn't it?
Anyway, Richard has already told you that there is no block scope in
ECMAScript.
[color=blue]
> It should be noted that some versions of Internet Explorer do support
> document.createElement() but support only the proprietary approach of
> a start tag instead of an element type identifier as argument for that
> method.[/color]
Which IE versions would that be? I am pretty sure that IE 5 and later
support document.createElement('tagname') while also supporting the
proprietary document.createElement('<tagname>') but I don't know of any
version that only supports the latter.
[color=blue][color=green]
>> input.type = 'hidden';
>> input.name = 'selectedURL';
>> input.value = input.defaultValue = 'http://example.com/documents';[/color]
>
>
> There is still the caveat here that the host object may not provide the
> properties accessed herewith.[/color]
[color=blue]
> Therefore, it appears to be wiser to check
> the properties accessed later for existence, too:
>
> if (input
> && typeof input.type != "undefined"
> && typeof input.name != "undefined"
> && typeof input.value != "undefined")[/color]
No, frankly with script in a HTML document as is usually the case in
this newsgroup and as it was certainly the case in that weeks old thread
you are following up to I think one can safely assume that the object
created with document.createElement('input') is a HTMLInputElement where
those properties can be set and those checks for properties would only
clutter the code then.
--
Martin Honnen
http://JavaScript.FAQTs.com/