/    Sign up×
Community /Pin to ProfileBookmark

Keeping focus on form page when errors are highlighted

I have a form where some elements validate onBlur(this bit’s working fine) and some elements validate onsubmitting the form.

the validation highlights the error fields for a nano second then the form obeys the “post” method. How do I tell it that if those messages are displayed it should not “post” but keep focus on the page.

The example script I adapted my code from has nothing in the form action, which is why it displays the errors.

how do you tell a form its ok to send to the server once all fields return valid?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@DokMay 15.2007 — To prevent default behaviour for any event

IE: event.returnValue = false;

FF: e.preventDefault = true;
Copy linkTweet thisAlerts:
@paulamcclauthorMay 15.2007 — To prevent default behaviour for any event

IE: event.returnValue = false;

FF: e.preventDefault = true;[/QUOTE]


where do I put this?
Copy linkTweet thisAlerts:
@DokMay 15.2007 — In the event handler function

function handle() {

window.event ? window.event.returnValue = false e.prventDefault = true;

}

<form onsubmit="handle();">

...

</form>
×

Success!

Help @paulamccl 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,
)...