/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Onsubmit clear form – how?

Hi.

I have this form which opens a new page after submitting the info. I would like to be able to clear the form after it’s submitted.

[code=html]<form name=”login” method=”post” action=”https://www.domain.com/register” target=”_blank”>
<input type=”hidden” name=”iso” value=”gb” />
<input type=”text” name=”username” value=”” />
<input type=”password” name=”password” value=”” />
<input type=”submit” name=”login_btn” value=”Register” />
</form>[/code]

How do I achieve that?

Thanks in advance.

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@OfekmeisterOct 05.2010 — [CODE]document.body.all.tags('input').value = '';[/CODE]

or http://www.w3schools.com/input_type_reset
Copy linkTweet thisAlerts:
@meekauthorOct 06.2010 — Hi and thanks.

Where do I put this? The input fields should only be cleared [I]after [/I]submitting.
Copy linkTweet thisAlerts:
@FangOct 06.2010 — [CODE]function passInfo(f) {
f.submit();
setTimeout(function(){f.reset();},1000);
return false;
}
[/CODE]
[CODE]<form name="login" method="post" action="https://www.domain.com/register" onsubmit="return passInfo(this)" target="_blank">
[/CODE]


This only works in IE, don't use it [COLOR="Red"]document.body.all.tags[/COLOR]
Copy linkTweet thisAlerts:
@meekauthorOct 06.2010 — Hi Fang.

Seems to work fine. Thanks a lot.

Kind regards.
Copy linkTweet thisAlerts:
@OfekmeisterOct 06.2010 — I know this is resolved but, I have a question Fang. If one's wireless signal isn't phenomenal by any means, wouldn't this clear the form data before it gets fully submitted or do browsers store the information immediately first?
Copy linkTweet thisAlerts:
@FangOct 07.2010 — The 2nd window must receive the data before clearing the form. With slow connection times, increase the delay.

Alternatively, if you have control over the 2nd window, add the following to the document in the 2nd window[CODE]window.onload=function() {
if(opener.document.login) {opener.document.login.reset();}
};
[/CODE]
Copy linkTweet thisAlerts:
@meekauthorOct 07.2010 — Fang - thanks a lot. I have added your code to the 2nd window. I guess I still need to keep the other code in the form in the first window?

What exactly does this second piece of code do?
Copy linkTweet thisAlerts:
@FangOct 07.2010 — Use one of the scripts, not both.

The 2nd script tests for the existence of the 1st window(opener) and the form, if it exists it clears the form.

Use this script in preference to the other script.
×

Success!

Help @meek 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.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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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