/    Sign up×
Community /Pin to ProfileBookmark

form keeps moving to the top of page

Hi Guys

I have a form and am using the onClick handler to process my data. The problem is when I click the button the page moves to the top and I don’t want it to do that. Its really annoying because if I am half way down a page and it moves to the top then I will have to re-scroll back down again. See code below:

[CODE]<form action=”#”>
<input type=”submit” value=”Proceed” onclick=”loadContent(‘payment’)”/>
</form>[/CODE]

How can I stop this from happening?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Jul 11.2008 — You are telling it to with action="#". There are two ways around it, I think I'd prefer the first.<i>
</i>&lt;form action="#formtag" id="formtag"&gt;
&lt;input type="submit" value="Proceed" onclick="loadContent('payment')"/&gt;
&lt;/form&gt;
OR<i>
</i>&lt;form action="#" onsubmit="return false;"&gt;
&lt;input type="submit" value="Proceed" onclick="loadContent('payment')"/&gt;
&lt;/form&gt;
Copy linkTweet thisAlerts:
@mityaJul 12.2008 — Shaolin - the reason it was jumping was because the form's action was sending the browser to an anchor that didn't exist. In these cases, the browser always goes to the top of the page. Either of Declan's methods will sort you out.
×

Success!

Help @Shaolin spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...