/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] JQuery: how to stop refresh after submit press?

Hey

Im having some problems with the $(“form”).submit() function in JQuery. When i press the submit button the <div id=”formOutput”></div> should display Validating… and it does. The problem is that when i press the submit button the page also refreshes, so the display of Validating is only showing at the time where the page havent got to refresh yet.

How do i stop the refresh of the page, when i press the submit button?

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@JJohnsenDKauthorJan 03.2009 — forgot to put code with :/

[CODE]
// Do something with submit
$("form").submit(function() {
if ($("input:first").val()) {
$("#formOutput").html("Validated...").show();
return true;
}
$("#formOutput").text("Not valid!").show().fadeOut(1000);
return false;
});
[/CODE]


[code=html]
<div>
<form method="post" action="#">
<input type="text" name="name" />
<input type="submit" name="submit" value="send" />
</form>
</div>
<div id="formOutput">

</div>
[/code]
Copy linkTweet thisAlerts:
@FangJan 03.2009 — If the data is 'not valid' it won't refresh
Copy linkTweet thisAlerts:
@JJohnsenDKauthorJan 03.2009 — i am aware of that, but my problem is that it should refresh anytime. Why does it not refresh if the data is 'not valid' and why does it refresh when it is valid?
Copy linkTweet thisAlerts:
@FangJan 03.2009 — Use [I]return true[/I] for both cases.
Copy linkTweet thisAlerts:
@JJohnsenDKauthorJan 03.2009 — i figured it out... thanks for your help
×

Success!

Help @JJohnsenDK 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 5.2,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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