From: ibizara on
> Bart Van der Donck

> <body onLoad="if (document.getElementById('search'))
> document.getElementById('search').focus();">

Perfect and as this is for a local intranet everyone has IE7 so many
thanks works great :)

Thanks to all other replies :D
From: Thomas 'PointedEars' Lahn on
ibizara wrote:
> Bart Van der Donck [wrote:]
>> <body onLoad="if (document.getElementById('search'))
>> document.getElementById('search').focus();">
>
> Perfect and as this is for a local intranet everyone has IE7 so many
> thanks works great :)

Nevertheless, it is needlessly inefficient (and error-prone). Consider this
more efficient and slightly less error-prone solution:

<body onLoad="var o = document.getElementById('search');
if (o && o.focus) o.focus();">

Consider more feature-testing for an even less error-prone solution. YOu
should also consider that now everyone there may be using IE 7 but that will
change in the future. As a responsible developer you should be prepared for
that event as much as you can so that little to no further development costs
will have to be invested then. Implementing feature tests helps a great
deal in achieving that.

> Thanks to all other replies :D

You're welcome.


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7(a)news.demon.co.uk>
From: Randy Webb on
Thomas 'PointedEars' Lahn said the following on 12/23/2007 5:29 PM:
> ibizara wrote:
>> Bart Van der Donck [wrote:]
>>> <body onLoad="if (document.getElementById('search'))
>>> document.getElementById('search').focus();">
>> Perfect and as this is for a local intranet everyone has IE7 so many
>> thanks works great :)
>
> Nevertheless, it is needlessly inefficient (and error-prone). Consider this
> more efficient and slightly less error-prone solution:
>
> <body onLoad="var o = document.getElementById('search');
> if (o && o.focus) o.focus();">

Hmm. A "solution" that is still highly error-prone. Maybe you should
Google this thread and read it - in its entirety - to find out why it is
not as "simple" as you portray it to be. Just because an element has a
"focus" property doesn't mean you can set focus to it.

> Consider more feature-testing for an even less error-prone solution.

A *lot* more feature-testing. Especially in IE.

As it is, I can post code that will "break" even your "quick-hack" in at
least 4 different ways. Two of which I have already posted.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
From: David Mark on
On Dec 23, 5:49 pm, Randy Webb <HikksNotAtH...(a)aol.com> wrote:
> Thomas 'PointedEars' Lahn said the following on 12/23/2007 5:29 PM:
>
> > ibizara wrote:
> >> Bart Van der Donck [wrote:]
> >>> <body onLoad="if (document.getElementById('search'))
> >>> document.getElementById('search').focus();">
> >> Perfect and as this is for a local intranet everyone has IE7 so many
> >> thanks works great :)
>
> > Nevertheless, it is needlessly inefficient (and error-prone).  Consider this
> > more efficient and slightly less error-prone solution:
>
> >   <body onLoad="var o = document.getElementById('search');
> >                 if (o && o.focus) o.focus();">
>
> Hmm. A "solution" that is still highly error-prone. Maybe you should
> Google this thread and read it - in its entirety - to find out why it is
> not as "simple" as you portray it to be. Just because an element has a
> "focus" property doesn't mean you can set focus to it.

No, but it is something that cannot be stipulated by the developer
(unlike the initial visibility, display and disabled states.) I am
surprised to see "PointedEars" testing a method by boolean type
conversion though. We've been over that.

>
> > Consider more feature-testing for an even less error-prone solution.
>
> A *lot* more feature-testing. Especially in IE.

Which (as I think you previously mentioned) would be a complete waste
of time (unless you are trying to defend against user style sheets.)
And IIRC, IE doesn't support user style sheets.

>
> As it is, I can post code that will "break" even your "quick-hack" in at
> least 4 different ways. Two of which I have already posted.

The less said about that "quick-hack" the better. The usual
translation for that is "bad-code."
From: Randy Webb on
David Mark said the following on 12/23/2007 6:09 PM:
> On Dec 23, 5:49 pm, Randy Webb <HikksNotAtH...(a)aol.com> wrote:
>> Thomas 'PointedEars' Lahn said the following on 12/23/2007 5:29 PM:
>>
>>> ibizara wrote:
>>>> Bart Van der Donck [wrote:]
>>>>> <body onLoad="if (document.getElementById('search'))
>>>>> document.getElementById('search').focus();">
>>>> Perfect and as this is for a local intranet everyone has IE7 so many
>>>> thanks works great :)
>>> Nevertheless, it is needlessly inefficient (and error-prone). Consider this
>>> more efficient and slightly less error-prone solution:
>>> <body onLoad="var o = document.getElementById('search');
>>> if (o && o.focus) o.focus();">
>> Hmm. A "solution" that is still highly error-prone. Maybe you should
>> Google this thread and read it - in its entirety - to find out why it is
>> not as "simple" as you portray it to be. Just because an element has a
>> "focus" property doesn't mean you can set focus to it.
>
> No, but it is something that cannot be stipulated by the developer
> (unlike the initial visibility, display and disabled states.) I am
> surprised to see "PointedEars" testing a method by boolean type
> conversion though. We've been over that.

Nothing Thomas does surprises me anymore. And I do mean *nothing*.

>>> Consider more feature-testing for an even less error-prone solution.
>> A *lot* more feature-testing. Especially in IE.
>
> Which (as I think you previously mentioned) would be a complete waste
> of time (unless you are trying to defend against user style sheets.)

input{
visibility: hidden;
display: none;
}

Damn that was rude :)

> And IIRC, IE doesn't support user style sheets.

It does. Tools>Internet Options>General>Accessibility>Format Documents
using my style sheet.

>> As it is, I can post code that will "break" even your "quick-hack" in at
>> least 4 different ways. Two of which I have already posted.
>
> The less said about that "quick-hack" the better. The usual
> translation for that is "bad-code."

And he always tries to defend it by saying "I said it was a quick hack"
which usually translates to "I didn't have a clue about it, just wanted
to reply".

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6
Prev: print(), iframe, IE 5/6
Next: Request.Form in Javascript