Actually window.location is better than document.location, which before JS 1.0 was read only. Anchors only work from JS2.0 on anyway.

Putting a new URL into window.location makes the browser load a new page, but using an anchor name should only make it scroll to display that anchor without reloading the page.

You can also (if you want to work harder) take advantage of the fact that anchors have x and y properties that specify their location on the page, and ScrollTo() requires x and y values which you can get from the anchor: something like Window.ScrollTo(Anchors[fieldname].x, Anchors[fieldname].y); but I suspect this would do exactly the same as Window.Location='fieldname'; and take a lot more typing!

Have fun
Bj

----- Original Message ----- From: "Bj" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Monday, June 26, 2006 6:52 PM
Subject: Re: [wdvltalk] Scrolling in Javascript


----- Original Message ----- From: "Elankumaran"
The page is very long and the validation fires onclick of the Submit button at the bottom of the page. Now if a validation fails for a form field at the
top/middle of the page, though the error is displayed next to that field,
the user is required to scroll back to that specific location in the page to
view the error.
I would want to scroll the page automatically to the position where the
error occurred.

How about putting <a name="fieldname"></a> anchors at each field, and using document.location="#fieldname" to jump to them?

Bj

____ . The WDVL Discussion List from WDVL.COM . ____
To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED] or use the web interface http://e-newsletters.internet.com/discussionlists.html/
      Send Your Posts To: [email protected]
To change subscription settings, add a password or view the web interface:
http://intm-dl.sparklist.com/read/?forum=wdvltalk

________________  http://www.wdvl.com  _______________________

You are currently subscribed to wdvltalk as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
To unsubscribe via postal mail, please contact us at:
Jupitermedia Corp.
Attn: Discussion List Management
475 Park Avenue South
New York, NY 10016

Please include the email address which you have been contacted with.


____ • The WDVL Discussion List from WDVL.COM • ____
To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED] or
use the web interface http://e-newsletters.internet.com/discussionlists.html/
      Send Your Posts To: [email protected]
To change subscription settings, add a password or view the web interface:
http://intm-dl.sparklist.com/read/?forum=wdvltalk

________________  http://www.wdvl.com  _______________________

You are currently subscribed to wdvltalk as: [email protected]
To unsubscribe send a blank email to [EMAIL PROTECTED]
To unsubscribe via postal mail, please contact us at:
Jupitermedia Corp.
Attn: Discussion List Management
475 Park Avenue South
New York, NY 10016

Please include the email address which you have been contacted with.

Reply via email to