Forum Moderators: open

Message Too Old, No Replies

Page refreshes after onClick event!

I don't want that to happen...

         

digitize

9:16 pm on Nov 1, 2005 (gmt 0)

10+ Year Member



I've got a web form that is supposed to automatically go to a specific part of the form everytime a user clicks a certain radio button. The problem is that I don't want it to refresh (losing all of the info previously entered into the form). The link is relative and stays on the same page and this doesn't happen w/ the same code on a regular PC, just pocket PC. It seems to have to do with the window.location.href java. Does anyone know of a different method for this?

<input type="radio" value="0" name="M0200_REG_CHG_14_DAYS" onclick="window.location.href='#M0220'">

Thanks,
Matt

RonPK

8:21 am on Nov 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you can use ID's instead of named anchors, this snippet should work:

onclick="window.scrollTo(0, document.getElementById('M0220').offsetTop);"

That should make the browser scroll to the top of the element with ID 'M0220'.

kaled

11:39 am on Nov 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You might consider using element.scrollIntoView();

Kaled.

RonPK

10:57 am on Nov 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> element.scrollIntoView();

Nice; I didn't know that one. Unfortunately Opera (8.5/Win) doesn't support it. IE6 and FF do.

kaled

12:33 pm on Nov 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I just tested a form validation demo on my own site that uses element.ScrollIntoView(). Opera 8.5 seems to work correctly. However, I also use element.focus() in the demo so that may be a factor.

Kaled.

RonPK

2:04 pm on Nov 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah, must be the focus() that gets your page scrolling in Opera. A bit of Googling tells me scrollIntoView() is a MS-invention that has been adopted by Firefox - and probably by the other Gecko's as well. Like Opera, Safari (on OS 10.3) doesn't do much with it either.

window.scrollTo(x, y) requires a bit more code but seems to be more widely supported.

digitize

3:06 pm on Nov 7, 2005 (gmt 0)

10+ Year Member



Couldn't get either to work on the PPC. Works fine on a regular PC though. I'll just stick w/ the regular link for now. Thanks for the info though!