[BNM] Modular javascript for forms....
David Andrew
david.andrew at gmail.com
Tue Aug 21 12:46:37 BST 2007
On 16/08/07, Dan Eastwell <daneastwell at gmail.com> wrote:
I saw this used the otherday on a google map script using
'addLoadEvent' to call a function after the page has loaded
there is a full decription and comments here:
http://simonwillison.net/2004/May/26/addLoadEvent/
Apparently addEvent fails silently in IE5/Mac
> On 8/14/07, paul perrin <paul at idltd.com> wrote:
> >
> > Hi
> >
> > Thanks for all the input - just so you know - in the end I went with
> > something like....
> >
> > Javascript function:-
> >
> > function addEvent(obj, evType, fn){
> > if (obj.addEventListener){
> > obj.addEventListener(evType, fn, false);
> > } else if (obj.attachEvent){
> > var r = obj.attachEvent("on"+evType, fn);
> > } }
> >
> > And if validation fails, the following is injected into the page:-
> >
> > <script language='JavaScript'>addEvent(window,'load',function() {
> > document.myform.dufffield.focus();})</script>
> >
> > I had a bit of a problem initally when I was passing in a fuction as a
> > parameter (it actually called the function as the page loaded and the
> > actual
> > event was set to nonsense - Doh! took a bit of time to get to the bottom
> > of
> > that one) - but it all works fine now!
> >
> > The next problem was that setting focus put the input field on the very
> > bottom line of the browser window - which looked naff, so I set focus to
> > the
> > last field and then immediately to the problem field, but this put the top
> > of the form off the top of the window (on any reasonably sized screen)
> > which
> > also looked naff, so currently it actually sets focus to a field in
> > the middle of the form, and then immediately to the problem field. The
> > user
> > doesn't see this, they just get the problem field somewhere in the middle
> > of
> > their screen - yay!
> >
> > This isn't usually a problem, but this is a long page, with the form way
> > down near the bottom.
> >
> >
> --
>
> BNM Subscribe/Unsubscribe:
> http://www.brightonnewmedia.org/options/bnmlist
>
> BNM info/archives:
> http://www.brightonnewmedia.org/
>
> BNM powered by Wessex Networks:
> http://www.wessexnetworks.com
>
More information about the BNMlist
mailing list. Powered by Wessex Networks